C. White Sheet(思维+几何基础)
程序员文章站
2022-03-30 08:24:28
...
https://codeforces.com/problemset/problem/1216/C
思路:
需要转化成白块与两块黑的∩的总面积,为了处理两个黑的重叠面积,然后白块去掉其重复部分,再比较白与黑的总相交面积是否达到白块的面积
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL getarea(LL x1,LL y1,LL x2,LL y2,LL x3,LL y3,LL x4,LL y4){
LL x5=max(x1,x3);
LL y5=max(y1,y3);
LL x6=min(x2,x4);
LL y6=min(y2,y4);
LL s=(x6-x5)*(y6-y5);
if(x5>x6||y5>y6) return 0;
else return s;
}
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
LL x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6; cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4>>x5>>y5>>x6>>y6;
LL s1=(x2-x1)*(y2-y1);
///求S2∩S3的矩形坐标
LL x7=max(x3,x5);
LL y7=max(y3,y5);
LL x8=min(x4,x6);
LL y8=min(y4,y6);
LL s4=getarea(x1,y1,x2,y2,x7,y7,x8,y8);///S1∩S4;
LL s2=getarea(x1,y1,x2,y2,x3,y3,x4,y4);///S1∩S2;
LL s3=getarea(x1,y1,x2,y2,x5,y5,x6,y6);///S1∩S3;
LL sum=s2+s3-s4;
if(s1<=sum) cout<<"NO"<<"\n";
else cout<<"YES"<<"\n";
return 0;
}