题目地址:http://codeforces.com/contest/749/problem/B
题意:告诉你三个点,让你求出一个点的集合,让集合中的每个点都可以与已知的三个点构成一个平行四边形。
思路:通过公式得出结果,再用set去重,这题主要我记录的是自定义set去重
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#define N 300
#define LL long long
#define inf 0x3f3f3f3f
using namespace std;
const double eps = 1e-9;
struct node {
int x, y;
node(int aa, int bb) {
x = aa;
y = bb;
}
bool operator < (const node &a)const {
if (a.x == x&&a.y == y) {
return false;
}
else {
if (a.x == x) {
return y < a.y;
}
return x < a.x;
}
}
};
int main() {
cin.sync_with_stdio(false);
int x[4], y[4];
set<node> s;
while (cin >> x[0] >> y[0]) {
for (int i = 1; i < 3; i++) {
cin >> x[i] >> y[i];
}
s.clear();
s.insert(node(x[0] + x[1] - x[2], y[0] + y[1] - y[2]));
s.insert(node(x[0] + x[2] - x[1], y[0] + y[2] - y[1]));
s.insert(node(x[2] + x[1] - x[0], y[2] + y[1] - y[0]));
cout << s.size() << endl;
for (set<node> ::iterator it = s.begin(); it != s.end(); it++) {
cout << it->x << " " << it->y << endl;
}
}
return 0;
}