Clarke and five-pointed star
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 182 Accepted Submission(s): 110
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 numbers xi,yi(−109≤xi,yi≤109) , denoting the coordinate of this point.
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 . )
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 NoHint![]()
![]()
Source
出题人:
容易看出只需要判断这5个点是否在一个正五边形上。
因此我们枚举排列,然后依次判断即可。
判定方法是,五条相邻边相等,五条对角线相等。
当然题目给的精度问题,窝只能说,如果泥做法不复杂,精度足够好的话,是可以过的。
毕竟题目说的小于10−4是指理论上的,所以理论上适用所有的数之间的比较。
所以有人问我开方前和开方后,我只能说,哪个精度高用哪个....
当然你也可以先求出凸包然后再判相邻距离......
比赛时SB了,哎。。。
这么简单的题目还没敲出来。
排序的地方忘记return 。。。比赛时 找了好久也没找到怎么错了
BestCoder 又掉分了 。。。
以后要仔细。
#include
#include
#include
#include
using namespace std;
double x[10],y[10];
int h[10];
struct node
{
int x;
double y;
} b[10];
bool cmp(node l,node r)
{
return l.y
2) continue; for(j=0; j<5; j++) { if(i==j||h[j]>2) { b[j].y=10000000000000000000; b[j].x=j; continue; } b[j].y=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); b[j].x=j; } sort(b,b+5,cmp); if(abs(b[1].y-b[0].y)<0.0001) { if(h[b[0].x]<=2&&h[b[1].x]<=2) { h[i]++; h[b[0].x]++; h[b[1].x]++; flag=1; } else flag=0; } else flag=0; if(flag==0) break; } if(flag) printf("Yes\n"); else printf("No\n"); } return 0; }