UVA - 1595

点关于直线对称,点匹配问题,可以用set,即在集合里找有没有匹配的点,

先不管y,只看x,如果要关于y轴对称当x从小到大排时,对称轴在中间,可以看出来为平均数,

假设求(x1,y1)的对称点(x2,y2)那么y1一定等于y2且(sumx/n)*2==(x1+x2)化简x2=sumx*2/n-x1;

可能出现sumx*2/n除不尽的情况,那就所有的x乘以n

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstdlib>
#include<cctype>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
const double INF=1e10;
const int len=1e3+5;
const ll mod=1e9+7;
P p[len];
set<P>se;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		se.clear();
		int n;
		scanf("%d",&n);
		for(int i=1;i<=n;++i)scanf("%lld%lld",&p[i].first,&p[i].second),p[i].first*=n,se.insert(p[i]);
		ll sumx=0;
		for(int i=1;i<=n;++i)
			sumx+=p[i].first;
		int flag=0;
		for(int i=1;i<=n;++i)
			if(se.count(P(2*sumx/n-p[i].first,p[i].second))==0)flag=1;
		if(flag)puts("NO");
		else puts("YES");

	}
}

猜你喜欢

转载自blog.csdn.net/hutwuguangrong/article/details/81411551