NKOJ 1353 图形面积
|
问题描述
桌面上放了N个矩形,这N个矩形可能有互相覆盖的部分,求它们组成的图形的面积。(矩形的边都与坐标轴平行)
输入格式
输入第一行为一个数N(1≤N≤100),表示矩形的数量。下面N行,每行四个整数,分别表示每个矩形的左下角和右上角的坐标,坐标范围为 到 之间的整数。
输出格式
输出只有一行,一个整数,表示图形的面积。
样例输入
3
1 1 4 3
2 -1 3 2
4 0 5 2
样例输出
10
#include<cstdio>
#include<cmath>
#include<cctype>
#include<algorithm>
#define ll long long
#define maxn 203
using namespace std;
int n, tot_x, tot_y;
ll ans;
ll X[maxn], Y[maxn], Renew_X[maxn], Renew_Y[maxn], Map[maxn][maxn];
char buf[ << ], *p1 = buf, *p2 = buf, obuf[ << ], *O = obuf;
bool Mark[maxn][maxn];
struct node {
ll x1, x2, y1, y2, xx1, xx2, yy1, yy2;
}Pair[maxn];
namespace Ironclad_Programming {
#define R register int
#define For(i, s, n) for (R i = s; i <= n; ++ i)
#define Getch() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1 ++)
inline ll read() {
int x = , f = ;
char ch = Getch();
while(!isdigit(ch)){if (ch == '-')f = -; ch = Getch();}
while(isdigit(ch))x = x * + (ch ^ ), ch = Getch();
return x * f;
}
void write(ll x) {
if (x > ) write(x / );
*O ++ = x % + '';
}
namespace ini {
int j = ;
void Discretization() {
Renew_X[] = abs(X[]);
Renew_Y[] = abs(Y[]);
For (i, , * n) {
if (X[i] > X[i - ]) {
Renew_X[++ tot_x] = X[i] - X[i - ];
X[tot_x] = X[i];
}
if (Y[i] > Y[i - ]) {
Renew_Y[++ tot_y] = Y[i] - Y[i - ];
Y[tot_y] = Y[i];
}
}
}
void Convert() {
int j;
For (i, , n) {
j = lower_bound(X + , X + tot_x, Pair[i].x1) - X;
if (X[j] == Pair[i].x1)Pair[i].xx1 = j;
j = lower_bound(X + , X + tot_x, Pair[i].x2) - X;
if (X[j] == Pair[i].x2)Pair[i].xx2 = j;
j = lower_bound(Y + , Y + tot_y, Pair[i].y1) - Y;
if (Y[j] == Pair[i].y1)Pair[i].yy1 = j;
j = lower_bound(Y + , Y + tot_y, Pair[i].y2) - Y;
if (Y[j] == Pair[i].y2)Pair[i].yy2 = j;
}
}
void executive() {
n = read();
For (i, , n) {
Pair[i].x1 = read(), Pair[i].y1 = read(), Pair[i].x2 = read(), Pair[i].y2 = read();
++ j;
X[j] = Pair[i].x1;
Y[j] = Pair[i].y1;
++ j;
X[j] = Pair[i].x2;
Y[j] = Pair[i].y2;
}
sort(X + , X + * n + );
sort(Y + , Y + * n + );
Discretization();
Convert();
}
}
void solve() {
For (i, , tot_y)
For (j, , tot_x)
Map[i][j] = Renew_Y[i] * Renew_X[j];
For (i, , n)
For (j, Pair[i].yy1 + , Pair[i].yy2)
For (k, Pair[i].xx1 + , Pair[i].xx2)
Mark[j][k] = ;
For (i, , tot_y)
For (j, , tot_x)
if (Mark[i][j])
ans += Map[i][j];
write(ans);
}
void Main() {
ini::executive();
solve();
fwrite(obuf, O - obuf, , stdout);
}
#undef R
#undef For
#undef Getch
}
int main() {
Ironclad_Programming::Main();
return ;
}
NKOJ 1353 图形面积的更多相关文章
- 前端学PHP之面向对象系列第六篇——简单图形面积计算器实现
前面的话 本文用面向对象的技术来实现一个简单的图形面积计算器 图形类 //rect.class.php <?php abstract class Shape{ public $name; abs ...
- 递推DP URAL 1353 Milliard Vasya's Function
题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...
- URAL 1353 Milliard Vasya's Function(DP)
题目链接 题意 : 让你找出1到10^9中和为s的数有多少个. 思路 : 自己没想出来,看的题解,学长的题解报告 题解报告 //URAL 1353 #include <iostream> ...
- ural 1353. Milliard Vasya's Function
http://acm.timus.ru/problem.aspx?space=1&num=1353 #include <cstdio> #include <cstring&g ...
- C++习题 虚函数-计算图形面积
C++习题 虚函数-计算图形面积 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 122 Solved: 86 [cid=1143&pid=6 ...
- ural 1353. Milliard Vasya's Function(背包/递归深搜)
1353. Milliard Vasya's Function Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning ma ...
- ural 1353. Milliard Vasya's Function(dp)
1353. Milliard Vasya's Function Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning ma ...
- 51nod 1353 树 | 树形DP经典题!
51nod 1353 树 | 树形DP好题! 题面 切断一棵树的任意条边,这棵树会变成一棵森林. 现要求森林中每棵树的节点个数不小于k,求有多少种切法. 数据范围:\(n \le 2000\). 题解 ...
- C++继承与多态练习--计算图形面积
1.目的: /*设计一个计算图形面积的类库. 类库的顶层是一个抽象类,并且提供三个纯虚函数:显示数据成员.返回面积和返回体积. Class Shape { virtual void showData( ...
随机推荐
- angular的开始历程
开始写angular了,抑制不住的开心,比react差点开心,vue开始太虐 喜欢一个人要不要表个白?其实也没啥资格喜欢~!!考虑一段时间吧 9.29表白了,嗯,被拒绝的干脆利落 为他写了一首小诗歌, ...
- 内网渗透之权限维持 - MSF
年初九 天公生 0x034 MSF(美少妇) 启动msf msfconsole 先启动msf依赖的postgresql数据库 初始化数据库 msfdb init (要用普通用户) msf路径 /usr ...
- flask 对于邮件url进行一个加密防止爆破
注册表单 from app.modles import User class registerForm(FlaskForm): nicheng = StringField('昵称',validator ...
- video标签加载视频有声音却黑屏
问题 昨天用户上传了一个视频文件,然而发现虽然有声音但是黑屏. 解释 因为原视频的编码是用 mp4v 格式的,它需要专用的解码器.而 chrome 并不支持,所以无法播放. 然后如果用转码功能转成用 ...
- JVM05——JVM类加载机制知多少
我们已经讲过 JVM 相关的很多常见知识点,感兴趣的朋友可以在我的往期文章中查看.接下来将继续为各位带来 JVM 类加载机制.关注我的公众号「Java面典」了解更多 Java 相关知识点. 类生命周期 ...
- 使用synchronized修饰静态方法和非静态方法有什么区别
前言 最近被问到了这个问题,第一次回答的也是很不好,在此参考网上答案进行整理记录.供大家学习参考. Synchronized修饰非静态方法 Synchronized修饰非静态方法,实际上是对调用该方法 ...
- 《ASP.NET Core 3框架揭秘》博文汇总
在过去一段时间内,写了一系列关于ASP.NET Core 3相关的文章,其中绝大部分来源于即将出版的<ASP.NET Core 3框架揭秘>(博文只能算是"初稿",与书 ...
- SQL逗号合并一列多行的值
select stuff((select ','+行名 from 表名 for xml path('')),1,1,'')
- org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout 和 RocketmqRemoting closeChannel: close the connection to remote address[] result: true
org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout ...
- 如何使用Postman编写Testlink测试用例
Postman2Testlink 通过Postman快速操作testlink测试用例.测试套件.测试计划.添加关键词.添加自定义字段等等. 工具地址 https://github.com/liyinc ...