缺失的拼图
#1552 : 缺失的拼图
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
小Hi在玩一个拼图游戏。如下图所示,整个拼图是由N块小矩形组成的大矩形。现在小Hi发现其中一块小矩形不见了。给定大矩形以及N-1个小矩形的顶点坐标,你能找出缺失的那块小矩形的顶点坐标吗?
输入
第一行包含一个整数,N。
第二行包含四个整数,(X0, Y0), (X'0, Y'0),代表大矩形左下角和右上角的坐标。
以下N-1行每行包含四个整数,(Xi, Yi), (X'i, Y'i),代表其中一个小矩形的左下角和右上角坐标。
对于30%的数据, 1 <= N <= 1000
对于100%的数据,1 <= N <= 100000 所有的坐标(X, Y)满足 0 <= X, Y <= 100000000
输出
输出四个整数(X, Y), (X', Y')代表缺失的那块小矩形的左下角和右上角的坐标。
样例输入
5
0 0 4 5
0 0 3 1
0 1 2 5
3 0 4 5
2 2 3 5
样例输出
2 1 3 2
//社会社会。。。其实,就是把所有矩形的顶点计数,如果是奇数,那么必定是,缺失的部分!
1 # include <cstdio> 2 # include <cstring> 3 # include <cstdlib> 4 # include <iostream> 5 # include <vector> 6 # include <queue> 7 # include <stack> 8 # include <map> 9 # include <bitset> 10 # include <sstream> 11 # include <set> 12 # include <cmath> 13 # include <algorithm> 14 # pragma comment(linker,"/STACK:102400000,102400000") 15 using namespace std; 16 # define LL long long 17 # define pb push_back 18 # define pr pair 19 # define mkp make_pair 20 # define lowbit(x) ((x)&(-x)) 21 # define PI acos(-1.0) 22 # define INF 0x3f3f3f3f3f3f3f3f 23 # define eps 1e-8 24 # define MOD 1000000007 25 26 inline int scan() { 27 int x=0,f=1; char ch=getchar(); 28 while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} 29 while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();} 30 return x*f; 31 } 32 inline void Out(int a) { 33 if(a<0) {putchar('-'); a=-a;} 34 if(a>=10) Out(a/10); 35 putchar(a%10+'0'); 36 } 37 # define MX 100005 38 /**************************/ 39 int n; 40 map<pr<int,int>,int> vis; 41 vector<pr<int,int> > v; 42 43 int main () 44 { 45 n = scan(); 46 int minX,minY,maxX,maxY; 47 minX = scan();minY = scan(); 48 maxX = scan();maxY = scan(); 49 50 v.pb( mkp(minX,minY) ); 51 vis[ mkp(minX,minY) ]++; 52 53 v.pb( mkp(minX,maxY) ); 54 vis[ mkp(minX,maxY) ]++; 55 56 v.pb( mkp(maxX,minY) ); 57 vis[ mkp(maxX,minY) ]++; 58 59 v.pb( mkp(maxX,maxY) ); 60 vis[ mkp(maxX,maxY) ]++; 61 62 for (int i=1;i<=n-1;i++) 63 { 64 int xx,yy,pp,kk; 65 xx = scan(); yy = scan(); 66 pp = scan(); kk = scan(); 67 if (vis[ mkp(xx,yy) ]==0) v.pb( mkp(xx,yy) ); 68 vis[ mkp(xx,yy) ]++; 69 70 if (vis[ mkp(xx,kk) ]==0) v.pb( mkp(xx,kk) ); 71 vis[ mkp(xx,kk) ]++; 72 73 if (vis[ mkp(pp,yy) ]==0) v.pb( mkp(pp,yy) ); 74 vis[ mkp(pp,yy) ]++; 75 76 if (vis[ mkp(pp,kk) ]==0) v.pb( mkp(pp,kk) ); 77 vis[ mkp(pp,kk) ]++; 78 } 79 80 int xxx = INF, yyy = INF, XXX = 0, YYY = 0; 81 for (int i=0;i<v.size();i++) 82 { 83 if (vis[v[i]]%2==0) continue; 84 xxx = min(xxx,v[i].first); yyy = min(yyy,v[i].second); 85 XXX = max(XXX,v[i].first); YYY = max(YYY,v[i].second); 86 } 87 printf("%d %d %d %d\n",xxx,yyy,XXX,YYY); 88 return 0; 89 }