HDU 5562 Clarke and five-pointed star (BC)
2016-07-15 20:14
591 查看
Clarke and five-pointed star
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other)
Total Submission(s) : 8 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a learner of geometric. When he did a research with polygons, he found he has to judge if the polygon is a five-pointed star at many times. There are 5 points on a plane, he wants to know if a five-pointed star existed with 5 points given.
Input
The first line contains an integer T(1≤T≤10),the number of the test cases.
For each test case, 5 lines follow. Each line contains 2 real numbers xi,yi(−109≤xi,yi≤109),
denoting the coordinate of this point.
Output
Two numbers are equal if and only if the difference between them is less than 10−4. For each test case, print Yes if
they can compose a five-pointed star. Otherwise, print No.
(If 5 points are the same, print Yes.
)
Sample Input
2 3.0000000 0.0000000 0.9270509 2.8531695 0.9270509 -2.8531695 -2.4270509 1.7633557 -2.4270509 -1.7633557 3.0000000 1.0000000 0.9270509 2.8531695 0.9270509 -2.8531695 -2.4270509 1.7633557 -2.4270509 -1.7633557
Sample Output
Yes No
Hint
Source
BestCoder Round #62 (div.2)分析:给出5个点的坐标,判断是否是一个正五角星
方法一:判断是正五角星,只需要判断是正五边形,因为输入的点是随机输入的,所以先把点按逆时针排一下序,然后再计算五边形的边是否相等即可。
方法二:把每个点到其他各点的距离求出来,排序,小的五条边是五边形的边,大的五条边是五边形的对角线。判断小的边相等,大的边相等即可。
代码如下(排序):
#include <stdio.h> #include <math.h> typedef struct node{ double x,y; double k; }Node; Node ans[10],left[10],right[10]; double sumx,sumy; void sort() {//点的排序 int i,j; sumx=sumx/5.0; sumy=sumy/5.0; int le,ri; le=ri=0; for(i=0;i<5;i++) { ans[i].k=(ans[i].y-sumy)/(ans[i].x-sumx); if(ans[i].x<=sumx) left[le++]=ans[i]; else right[ri++]=ans[i]; } for(i=0;i<le-1;i++) { for(j=i+1;j<le;j++) { if(left[i].k > left[j].k) { Node temp=left[i]; left[i]=left[j]; left[j]=temp; } } } for(i=0;i<ri-1;i++) { for(j=i+1;j<ri;j++) { if(right[i].k>right[j].k) { Node temp=right[i]; right[i]=right[j]; right[j]=temp; } } } int num=0; for(i=0;i<le;i++) ans[num++]=left[i]; for(i=0;i<ri;i++) ans[num++]=right[i]; } int main() { int T; int i; scanf("%d",&T); while(T--) { sumx=sumy=.0; for(i=0;i<5;i++) { scanf("%lf %lf",&ans[i].x,&ans[i].y); sumx+=ans[i].x; sumy+=ans[i].y; } sort(); double avg = sqrt((ans[0].x-ans[1].x)*(ans[0].x-ans[1].x)+(ans[0].y-ans[1].y)*(ans[0].y-ans[1].y)); int peace=0; for(i=1;i<4;i++) { double temp=sqrt((ans[i].x-ans[i+1].x)*(ans[i].x-ans[i+1].x)+(ans[i].y-ans[i+1].y)*(ans[i].y-ans[i+1].y)); if(fabs(avg - temp)<=0.0001) continue; else{ peace=1; break; } } if(!peace) printf("Yes\n"); else printf("No\n"); } return 0; }
相关文章推荐
- Java IO最详解
- Android项目工程目录结构说明及作用
- angular倒计时指令
- 离散化加树状数组求逆序数。
- 围棋棋盘有多少正方形
- 当 IDENTITY_INSERT 设置为 OFF 时,不能向表 '#TT' 中的标识列插入显式值。 sql server 临时表
- 浅谈C的printf
- 高性能IO模型浅析
- CAFFE-probuffer之二
- 牛客网编程题-超级子串
- 关于控件的width或者height设置成"0dp"的原因
- Android中的活动Activity
- 【SDOI2009】HH的项链
- Java 命令行运行参数大全
- 在zabbix上添加tcp连接数的监控项
- 二维树状数组poj1195
- android sqlite轻量级数据库的基本运用之创建数据库
- CAFFE-probuffer之一
- mysql性能调优:join查询(3)
- 小心!新媒体环境下,营销传播还有几个大坑!