AcWing 3203. 画图
题意:
在一个二维平面,给你n个矩形,要你求矩形面积的并。
思路:
n
∈
[
1
,
100
]
\in [1,100]
∈[1,100]
坐标的范围也是
∈
[
0
,
100
]
\in [0,100]
∈[0,100]
由于数据小所以直接暴力。
时间复杂度 O(
10
0
3
100^3
1003)
AC
# include <iostream>
# include <cstring>
# include <algorithm>
# define x first
# define y second
using namespace std;
typedef pair<int,int> pa;
int main(){
bool vis[200][200]{};
int n; cin>>n;
for(int i = 0; i < n ; i ++ ){
pa p1, p2;
cin>>p1.x>>p1.y>>p2.x>>p2.y;
// if(p1.x+p1.y > p2.x + p2.y)swap(p1,p2);
for(int dx = p1.x+1; dx<=p2.x; dx++) for(int dy = p1.y+1; dy <= p2.y; dy++)vis[dy][dx] = 1;
}
int ans = 0;
for(int i = 0; i <= 100; i ++ ){
for(int j = 0; j <= 100; j ++ )if(vis[i][j])ans++;
}
cout<<ans<<endl;
return 0;
}