Clarke and five-pointed star
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 242 Accepted Submission(s): 144
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 No
Hint
![](https://i-blog.csdnimg.cn/blog_migrate/79da2c5de8e2f04272848305de89daca.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/e94426a899410bd16158d74fc61c856d.jpeg)
Source
克拉克是一名人格分裂患者。某一天克拉克分裂为一个几何学习者,在研究多边形。 在研究某一个多边形的时候,克拉克发现他多次遇到判断5个点是否能组成一个五角星的问题,在这里,这5个点分别代表五角星的五个顶点(顶角上的点)。于是他跑来想你求助,让你写出一个程序快速判定。即对于给出的5个点,判断这5个点是否能组成一个五角星。官方题解:
容易看出只需要判断这5个点是否在一个正五边形上。
因此我们枚举排列,然后依次判断即可。
判定方法是,五条相邻边相等,五条对角线相等。
当然题目给的精度问题,窝只能说,如果泥做法不复杂,精度足够好的话,是可以过的。毕竟题目说的小于10^{-4}10−4是指理论上的,所以理论上适用所有的数之间的比较。所以有人问我开方前和开方后,我只能说,哪个精度高用哪个....
当然你也可以先求出凸包然后再判相邻距离......
个人看法:就是把每条边算一下就好了,后来感觉不是很对,以为还要算一下角度,以为错了,但是竟然对了,嘿嘿,上代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e3+5;
const int mod = 1000000007;
const double eps = 1e-4;
LL gcd(LL a, LL b)
{
if(b == 0)
return a;
return gcd(b, a%b);
}
struct node
{
double x,y;
} p[25];
double d[30];
double dis(node p1, node p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y));
}
int check()
{
for(int i=0; i<4; i++)
if(d[i+1]-d[i] > eps)
return 0;
return 1;
}
int main()
{
int k, T;
scanf("%d",&T);
while(T--)
{
k=0;
for(int i=0; i<5; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
for(int i=0; i<5; i++)
for(int j=i+1; j<5; j++)
d[k++] = dis(p[i],p[j]);
sort(d, d+10);
if(check())
printf("Yes\n");
else
printf("No\n");
}
return 0;
}