HDU-5563 (Clarke and five-pointed star)
来源:互联网 发布:xbox什么软件好玩 编辑:程序博客网 时间:2024/05/17 00:06
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
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
题意:给出任意顺序的5个点的坐标,判断5个点是否能连接成五角星,误差小于10^-4;
思路:首先想到的是判断是否为正五边形,想到用向量来解,结果因为坐标不是按照顺序给出的,,于是放弃这个思路。。。
然后从边的角度考虑,即判断边是否相等,要判断的边共有10条,里边五角星5条,外边围成的正五边形5条,,
若是五角星,则前后5条边必定不相等,且5条边内部分别相等,于是先排序,
再分别判断前5条边之间与后5条边之间是否相等。。即误差小于10^ -4;
以下AC代码:
#include<stdio.h>#include<stdlib.h>#include<math.h>int cmp(const void *a,const void *b){ return *(double *)a > *(double *)b ? 1 : -1;}int main(){ int t; double x[5],y[5]; double a[15]; int i,j; scanf("%d",&t); while(t--) { for(i=0;i<5;i++) { scanf("%lf%lf",&x[i],&y[i]); } int temp=0; int flag=1; for(i=0;i<5;i++) for(j=0;j<5,i!=j;j++) { a[temp++]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); //求出10条边 } qsort(a,temp,sizeof(a[0]),cmp); //从小到大排序 for(i=0;i<4;i++) { //判断前5条边之间是否相等 if(fabs(a[i]-a[i+1])>0.0001) { flag=0; break; } } for(i=5;i<9;i++) { //判断后5条边之间是否相等 if(fabs(a[i]-a[i+1])>0.0001) { flag=0; break; } } if(flag) printf("Yes\n"); else printf("No\n"); } return 0;}
1 0
- HDU 5563 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(判断正五边形)
- HDU 5563 Clarke and five-pointed star(暴力)
- HDOJ 5563 Clarke and five-pointed star
- HDU 5562 Clarke and five-pointed star (BC)
- HDOJ 5563 Clarke and five-pointed star(枚举)
- hdoj 5563 Clarke and five-pointed star 【判断五角星】
- hdoj--5563--Clarke and five-pointed star(简单几何)
- hdu5563 ( Clarke and five-pointed star )
- hdu5563 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】
- HDU 5563 Clarke and five-pointed star(判断正五边形)——BestCoder Round #62(div.1 div.2)
- BC-Clarke and five-pointed star(水)
- hdu5563 Clarke and five-pointed star(判正五边形,精度问题)
- BestCoder Round #62 (div.2) Clarke and five-pointed star
- Github iOS第三方库
- 剑指offer面试题19:二叉树的镜像
- 绝对定位与相对定位
- SSM连接数据库Mysql的配置
- Mac OS增删环境变量
- HDU-5563 (Clarke and five-pointed star)
- OpenStack Icehouse Installation - Multi Node
- oracle数据库_实例_用户_表空间之间的关系
- java网络socket编程(四)之Socket扩展1--实现单文件服务器
- 深入理解HDFS:Hadoop分布式文件系统
- Bitmap的两种方法
- 深刻理解和运用XMLHttpRequest
- EasyUI常用组件(基础)
- jPush极光推送tips,(ruby<2.2)