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

本文解析了CodeForces竞赛中的一道题目,该题目要求根据三个给定点找到所有可能构成平行四边形的点。文章提供了完整的C++代码实现,并介绍了如何利用自定义结构体和set容器进行去重。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目地址: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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值