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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值