WOJ1016-cherry Blossom

March is wonderful in Wuhan University for the blooming cherry blossoms. Walking in the campus, you can smell the fragrance and feel the 
romance with the tardiness falling of cherry blossom petals, and after a while you will see the ground will be covered by the beautiful 
blossom petals. 
  
Now, here comes the problem: the figure shown below is the cherry blossom petals on the ground, where the black points stand for blossom 
petals. And this figure on the left is up-down symmetric as it is possible to cut the figure into two identical halves by the dashed line 
shown in it, but the figure on the right is not. 
 
This figure shows the sample input data 

Given such a figure, can you tell me whether it is up-down symmetric or not. All the black points are different from each other. 

输入格式

There are multiple test cases.For each test case, it contains:
Line 1: One integer N (1<=N<=1000) which specifies the number of the cherry blossom petals in this test case.
Line 2?N+1: Two integers X and Y (you are ensured that the absolute value of both the integers are less than) which specify the position of the
cherry blossom petal.
Input will be terminated by EndOfFile.

输出格式

Print exactly one line for each test case. You should output YES if the figure is up-down symmetric, else output NO.

样例输入

5
0 0
2 0
1 1
0 2
2 2
4
0 0
2 0
1 1
0 2

样例输出

YES
NO


#include<stdio.h>
#include<stdlib.h>
int main() {
	int position[1000][2];
	int n,i,j;
	int x=0;

	while(scanf("%d",&n)==1) {
		int a[1000]= {};
		int b[1000]= {};
		x=0;
		for(i=0; i<n; i++)
			for(j=0; j<2; j++)
				scanf("%d",&position[i][j]);

		for(i=0; i<n; i++) {
			b[i]=0;
			for(j=0; j<n; j++)
				if(position[j][0]==position[i][0]) {
					b[i]+=position[j][1];
					a[i]++;
				}
		}

		for(i=0; i<n; i++)
			b[i]=b[i]/a[i];

		for(i=0; i<n; i++)
			if(b[i]==b[0])
				x++;

		if(x==n)
			printf("YES\n");
		else
			printf("NO\n");
	}
	system("pause");
	return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
typedef struct {
	int x; 
	int y;
} point;
const int N = 1000;
point d[N];
bool cmpx(point p1, point p2)
{ 
	return p1.x < p2.x;
}
bool cmpy(point p1, point p2)
{
	return p1.y < p2.y;
}
int main()
{
	int flag,n,axis,axisnew,j,k;
	while(cin >> n){
		flag = 1;
		for(int i = 0; i < n; i++)
		{
			cin >> d[i].x >> d[i].y;
		}
		sort(d, d + n, cmpx);
		int i = 0;
		for(i = 1; i < n; i++){
			if(d[i].x != d[0].x)
				break;
		}
		//find out the likely axis
		axis = 0;
		sort(d, d + i, cmpy);
		if(i & 1)
			axis = d[(i - 1) / 2].y;
		else
			axis = (d[i / 2]. y + d[i / 2 - 1].y) / 2;
		//test the axis
		for(int j = 0; j < i / 2; j++)
		{
			if((d[j].y + d[i - 1 - j].y) != 2 * axis){
				flag = 0;
				break;
			}
		}
		for(i = i; i < n && flag; ){
			for(j = i + 1 ; j < n; j++){
				if(d[j].x != d[i].x)
					break;
			}
			//find the new axis
			sort(d + i, d + j, cmpy);
			if((j - i) & 1)
				axisnew = d[(i + j-1) / 2].y;
			else
				axisnew = (d[(i + j) / 2].y + d[(i + j) / 2 - 1].y) / 2;
			//test the new axis
			for(k = 0; k < (j - i) / 2; k++){
				if(d[i + k].y + d[j - 1 - k].y != 2 * axisnew){
					flag = 0;
					break;
				}
			}
			if(axisnew^axis){
				flag = 0;
				break;
			}
			i = j;
		}
		if(flag)
			cout << "YES" << endl;
	 	else
			cout << "NO" << endl;
	}
	return 0;
}


全部评论

相关推荐

见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
牛客73617529...:无端端被你骂一句
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务