题意 :给出一个初始的黑白相间的棋盘 有两个人 第一个人先用白色染一块矩形区域
第二个人再用黑色染一块矩形区域 问最后黑白格子各有多少个
思路:这题的关键在于求相交的矩形区间
给出一个矩形的左下和右上角 则相交的条件为 max(X1,X3)<=min(X2,X4)&&max(Y1,Y3)<=min(Y2,Y4) 这里可以用线和线有公共区间的条件来推 矩形就是两个线
还有就是如果相交则求 相交的矩形的 左下和右上的坐标 ll xa=max(X1,X3),ya=max(Y1,Y3),xb=min(X4,X2),yb=min(Y2,Y4);
然后就是简单的容斥正常做就行了
#include<bits/stdc++.h>
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
#define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
#define F first
#define S second
#define pii pair<int ,int >
#define mkp make_pair
#define pb push_back
#define arr(zzz) array<ll,zzz>
using namespace std;
#define ll long long
#define int long long
const int maxn=3e5+;
const int inf=0x3f3f3f3f;
ll count(int x1,int y1,int x2,int y2,int o){//return black
ll n=x2-x1+;
ll m=y2-y1+;
ll white=,black=;
if(n&){
if(m&){
white=(n+)/+1ll*(n/+(n+)/)*(m/);
black=1ll*m*n-white;
}
else {
white=black=1ll*n*m/;
}
}
else {
white=black=1ll*n*m/;
}
if(o==){
return white;
}
else return black; }
void exchange(ll &x,ll&y){
ll tmp=x;
x=y;
y=tmp;
}
int32_t main(){
int t;
scanf("%lld",&t);
int n,m;
while(t--){
ll black=,white=;
int X1,Y1,X2,Y2,X3,Y3,X4,Y4;
scanf("%lld%lld",&n,&m);
scanf("%lld%lld%lld%lld%lld%lld%lld%lld",&X1,&Y1,&X2,&Y2,&X3,&Y3,&X4,&Y4);
if(n&){
if(m&){
white=(n+)/+ (n/+(n+)/)*(m/);
black=1ll*m*n-white;
}
else {
white=black=1ll*n*m/;
}
}
else {
white=black=1ll*n*m/;
}
ll tmp1=count(X1,Y1,X2,Y2,(X1+Y1)%==);
white-=1ll*(X2-X1+)*(Y2-Y1+)-tmp1;
white+=1ll*(X2-X1+)*(Y2-Y1+);
black-=tmp1;
ll tmp2=count(X3,Y3,X4,Y4,(X3+Y3)%==);
white-=1ll*(X4-X3+)*(Y4-Y3+)-tmp2;
black-=tmp2;
black+=1ll*(X4-X3+)*(Y4-Y3+);
/*if(X1<=X3){
exchange(X1,X3);
exchange(X2,X4);
exchange(Y1,Y3);
exchange(Y2,Y4);
}
if(){ }*/
ll minx=min(X1,X3);
ll miny=min(Y1,Y3);
if(max(X1,X3)<=min(X2,X4)&&max(Y1,Y3)<=min(Y2,Y4)){
ll xa=max(X1,X3),ya=max(Y1,Y3),xb=min(X4,X2),yb=min(Y2,Y4);
ll tmp=count(xa,ya,xb,yb,(xa+ya)%==);
//cout<<xa<<" "<<ya<<" "<<xb<<""<<yb<<" fuck"<<tmp<<endl;
black+=tmp;
white-=1ll*(xb-xa+)*(ya-yb+);
white+=1ll*(xb-xa+)*(ya-yb+)-tmp; }
cout<<white<<" "<<black<<endl;
} return ;
}