HDU 5562 Clarke and five-pointed star (BC)
来源:互联网 发布:逆波兰式计算c语言 编辑:程序博客网 时间:2024/06/10 03:47
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.
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 numbersxi,yi(−109≤xi,yi≤109) , denoting the coordinate of this point.
For each test case, 5 lines follow. Each line contains 2 real numbers
Output
Two numbers are equal if and only if the difference between them is less than 10−4 .
For each test case, printYes if they can compose a five-pointed star. Otherwise, print No . (If 5 points are the same, print Yes . )
For each test case, print
Sample Input
23.0000000 0.00000000.9270509 2.85316950.9270509 -2.8531695-2.4270509 1.7633557-2.4270509 -1.76335573.0000000 1.00000000.9270509 2.85316950.9270509 -2.8531695-2.4270509 1.7633557-2.4270509 -1.7633557
Sample Output
YesNo
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];elseright[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");elseprintf("No\n");}return 0;}
0 0
- HDU 5562 Clarke and five-pointed star (BC)
- HDU 5563 Clarke and five-pointed star
- HDU-5563 (Clarke and five-pointed star)
- BC-Clarke and five-pointed star(水)
- hdu 5563 Clarke and five-pointed star(几何)
- HDU 5563 Clarke and five-pointed star(判断正五边形)
- HDU 5563 Clarke and five-pointed star(暴力)
- hdu5563 ( Clarke and five-pointed star )
- hdu5563 Clarke and five-pointed star
- HDOJ 5563 Clarke and five-pointed star
- BestCoder Round #62 (div.2) HDU 5563 Clarke and five-pointed star
- hdu 5563 Clarke and five-pointed star 【BestCoder Round #62 (div.2) 1002】
- hdu5563 Clarke and five-pointed star(判正五边形,精度问题)
- HDOJ 5563 Clarke and five-pointed star(枚举)
- BestCoder Round #62 (div.2) Clarke and five-pointed star
- hdoj 5563 Clarke and five-pointed star 【判断五角星】
- hdoj--5563--Clarke and five-pointed star(简单几何)
- HDU 5563 Clarke and five-pointed star(判断正五边形)——BestCoder Round #62(div.1 div.2)
- 某服务请求经负载均衡设备分配到集群A、B、C、D进行处理响应的概率分别是10%、20%、30%和40%。已知测试集群所得的稳定性指标分别是90%、95%、99%和99.9%。现在该服务器请求处理失败,
- js实现全选和反选功能
- 小心!新媒体环境下,营销传播还有几个大坑!
- unity中鼠标和触摸问题
- 什么是野指针?如何避免野指针?
- HDU 5562 Clarke and five-pointed star (BC)
- July 15th 模拟赛C T4 回家(莫名其妙【推荐】) Solution
- [Database] 大数据量高并发的数据库优化详解
- python challenge 7学习过程
- C++11 lambda表达式 实际上是lua的闭包方式
- iOS中关于自定义模型的存储
- MATLAB学习记录
- Hibernate各种主键生成策略与配置详解
- 【Qt】标准输入对话框