2014年3月6日 星期四
[HOJ] 331 - 矩形交集
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;
struct P{
int x,b;
};
int cmp(P a,P b){
if(a.x!=b.x)
return a.x<b.x;
return a.b>b.b;
}
vector<P> X,Y;
int main(){
int t,n,i,j,L,R,a,b,c,d;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
L=0,R=0;
X.clear(),Y.clear();
for(i=0;i<n;i++){
scanf("%d%d%d%d",&a,&b,&c,&d);
X.push_back((P){min(a,c),1});
X.push_back((P){max(a,c),-1});
Y.push_back((P){min(b,d),1});
Y.push_back((P){max(b,d),-1});
}
sort(X.begin(),X.end(),cmp);
sort(Y.begin(),Y.end(),cmp);
int tmp=0;
for(i=0;i<X.size();i++){
//printf("%d.%d.\n",X[i].x,X[i].b);
tmp+=X[i].b;
if(tmp==n)
L=X[i+1].x-X[i].x;
}
tmp=0;
for(i=0;i<Y.size();i++){
tmp+=Y[i].b;
//printf("%d.%d.\n",Y[i].x,Y[i].b);
if(tmp==n)
R=Y[i+1].x-Y[i].x;
}
long long int ans=L;
ans*=R;
printf("%lld\n",ans);
}
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言