WOJ1016-cherry Blossom
来源:互联网 发布:倒计时软件安卓 编辑:程序博客网 时间:2024/06/04 21:40
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.
样例输入
50 02 01 10 22 240 02 01 10 2
样例输出
YESNO
#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");elseprintf("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 axisaxis = 0;sort(d, d + i, cmpy);if(i & 1)axis = d[(i - 1) / 2].y;elseaxis = (d[i / 2]. y + d[i / 2 - 1].y) / 2;//test the axisfor(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 axissort(d + i, d + j, cmpy);if((j - i) & 1)axisnew = d[(i + j-1) / 2].y;elseaxisnew = (d[(i + j) / 2].y + d[(i + j) / 2 - 1].y) / 2;//test the new axisfor(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; elsecout << "NO" << endl;}return 0;}
- WOJ1016-cherry Blossom
- hdu4085 Peach Blossom Spring
- hdu4085Peach Blossom Spring
- Peach Blossom Spring HDU
- HDU4085-Peach Blossom Spring
- cherry-pick
- UVa 1496 - Peach Blossom Spring
- git cherry-pick 小结
- git cherry-pick简介
- git cherry-pick 小结
- git cherry-pick
- Use git cherry-pick
- git cherry-pick
- git cherry-pick 小结 .
- git cherry-pick command
- git cherry-pick
- git cherry-pick
- git cherry-pick简介
- 最大连续子序列 HDU
- tf.train.shuffle_batch函数解析
- 苹果发iOS 11第8个测试版:预计正式版前最后一发
- NLTK05《Python自然语言处理》code04 编写结构化程序
- Java 流(Stream)、文件(File)和IO
- WOJ1016-cherry Blossom
- P3088突击小组
- JVM类加载机制
- fastjson 字段转换不区分大小写
- C#观察者模式
- 神奇6位数--蓝桥杯国赛j历年真题
- Ubuntu16.04安装redis和php的redis扩展
- 深入分析Docker镜像原理
- 斐波那契数列java实现