Problem symmetry axis 5_6 uva1595

I can not speak of a dish ...
This problem wa a night, scared, and I was deceived title, say good range of x is -10,000 to 10,000 do
me violence enumerate the x axis of symmetry of the wa ... one night, then the next day, test a little under the scope of x (write a cycle of death) - and sure enough, T ... a
really nonsense to say
that symmetric problem to catch their word, then it is easy to think that the axis of symmetry is the leftmost x and x of half the far right,
and because doing so may cause a floating point error appear floating point, then we can at the same time for all x * 2 ok, eliminate floating point
followed for as long as a judge from the first to the last , whether there is symmetry about the axis of symmetry of the point it can
determine whether it is the point of opening map <pair, int> friends on ok (direct violence find also, because little n)
on Code

#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6; 
typedef pair<int,int> point;
vector <point> dian;
int main()
{
	int t,n;
	scanf("%d",&t);
	while(t--)
	{
		dian.clear();  //注意清空 
		map <point,int> you; // 因为懒得写map 的清空,直接开里面 
		int ok  = 1,z = 0,xl,xr,mid; // xl,xr最左和最右 mid 对称轴 
		scanf("%d",&n);
		for (int i = 0; i < n; i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			x*=2;
			if(!i) 
			{
				xl = x;  xr = x;
			}
			if(x > xr) xr =x;
			if(x < xl) xl = x;
			point a = make_pair(x,y);
			dian.push_back(a);
			you[a] = 1;  //有这个点 
		}  
		mid = (xr+xl)/2;
			point w;
			for (int j = 0; j < n; j++)
			{
				
				int dis =  mid - dian[j].first;
				int k = mid + dis; //对称点的横坐标的计算 
				w = make_pair( k , dian[j].second);
				if(!you[w]) 
				{
					ok = 0; break;
				}
			}
		if(ok) printf("YES\n");
		else   printf("NO\n");
	}
	return 0;
}

Another way is to determine the axis of symmetry, as long as you can then sort the right (this sort needs to find the law, as detailed in the code), then the left directly to the right of the point, if the axis of symmetry right, and the same vertical axis, it is certainly MO have problems, but have to consider a case in point is the axis of symmetry, the vertical axis is not the same Mo was also the problem, if each point on ok ok
code below

#include <bits/stdc++.h>
using namespace std;
struct stu{
	int x,y;
}q[2000]; 
int comp(stu a, stu b)
{
	if(a.x == b.x) return a.y > b.y;
	return a.x < b.x;
}  //对称轴左边 按x从小到大 然后 x同时 y 先大后小 
int comp2(stu a, stu b)
{
	if(a.x == b.x) return a.y < b.y;
	return a.x < b.x;
} //对称轴右边同理 但 y 先小后大 可打出配合 
int main()
{
	int t,n,z,z1;
	cin>>t;
	while(t--)
	{
		cin>>n;
		for (int i = 0 ; i < n; i++)
		{
			scanf("%d%d",&q[i].x,&q[i].y);	q[i].x *= 2; 
		} 
		sort(q,q+n,comp);
		if(n>=4)  
		{
			int k = (n/2) + (n%2); //找规律 正确的排序 
			sort(q+k,q+n,comp2); 
		}		
		int ok = 1; //是否ok 
		int mid = 0;
		for (int i = 0; i < n/2; i++)
		{
			if(!i) 	mid = ( q[i].x + q[n-1-i].x ) /2;
			else if( mid != ( q[i].x + q[n-1-i].x )/2 )
			{
				ok = 0; break;
			} // 对称轴不行 
			if(q[i].y != q[n-1-i].y &&  (q[i].x != mid || q[n-1-i].x != mid))
			{
				ok = 0; break;
			} // 纵坐标不行 
		}
		if(ok) printf("YES\n");
		else   printf("NO\n"); 
	}
	return 0;
}

Published 55 original articles · won praise 1 · views 2656

Guess you like

Origin blog.csdn.net/qq_37548017/article/details/100097336
Recommended