时间限制:
10000ms
单点时限:
1000ms
内存限制:
256MB
-
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
描述
小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')代表缺失的那块小矩形的左下角和右上角的坐标。
思路:
把矩形的四个点算出来,统计一下,缺失的矩形的四个顶点出现的次数一定是奇数次
#include <iostream>
#include <set>
#include <map>
#include <vector>
using namespace std;
struct Node {
int x, y;
Node(int a, int b) {
x = a, y = b;
}
bool operator < (const Node &b) const {
if (x < b.x) return true;
else if (x == b.x ) {
if (y < b.y) return true;
else
return false;
}
return false;
}
};
void findAndInsert(set<Node> &S, Node tmp) {
set<Node>::iterator it;
it = S.find(tmp);
if ( it != S.end()) {
S.erase(tmp);
}
else {
S.insert(tmp);
}
}
void solve() {
int n, x1, y1, x2, y2, x3, y3, x4, y4;
cin >> n;
set<Node>S;
for (int i = 0; i < n; ++i) {
cin >> x1 >> y1 >> x2 >> y2;
x3 = x1, y3 = y2;
x4 = x2, y4 = y1;
Node leftDown = Node(x1, y1);
Node rightUp = Node(x2, y2);
Node leftUp = Node(x3, y3);
Node rightDown = Node(x4, y4);
findAndInsert(S, leftUp);
findAndInsert(S, leftDown);
findAndInsert(S, rightUp);
findAndInsert(S, rightDown);
}
set<Node>::iterator it = S.begin();
int cnt = 0;
for (; it != S.end(); ++it) {
if (cnt == 0 || cnt == 3) {
cout << (*it).x << " " << (*it).y << " ";
}
++cnt;
}
cout << endl;
}
int main() {
solve();
return 0;
}