Codeforces 749 B Parallelogram is Back(自定义set去重)

来源:互联网 发布:什么牌子的网络电视好 编辑:程序博客网 时间:2024/06/06 17:05

题目地址: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 0x3f3f3f3fusing 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;}
原创粉丝点击