UVA Symmetry

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;
struct node//集合中定义结构体
{
	int x, y;
	bool operator<(const node&s)const
	{
		return x < s.x || (x == s.x&&y < s.y);
	}
};//定义集合中的优先级
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		set<node>a;
		int n;
		cin >> n;
		int sum = 0;
		for (int i = 0; i < n; i++)
		{
			int x, y;
			cin >> x >> y;
			sum += x;
			node temp;
			temp.x = x * n; temp.y = y;
			a.insert(temp);//以n倍坐标遍历集合中可能的x坐标
		}
		set<node>::iterator it;
		bool flag = true;
		for (it = a.begin(); it != a.end(); it++)
		{
			node ans,record;
			ans = *it;
			record.x = 2 * sum - ans.x;//以两倍和进行做差检验
			record.y = ans.y;
			if (a.find(record) == a.end())
			{
				flag = false;
				break;
			}
		}
		if (flag)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	getchar();
	getchar();
	return 0;
}

1、对称问题,注意寻找横纵坐标关系
2、遍历问题,则联想set中find函数可快速寻找,储存坐标和,利用迭代器寻找

3、注意细节处理,利用两倍坐标和进行处理,小技巧
4、集合中涉及结构体,注意重新定义优先级,细节问题
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值