HDU 5563 Clarke and five-pointed star(判断正五边形)——BestCoder Round #62(div.1 div.2)

Clarke and five-pointed star

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)


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(1T10) , the number of the test cases. 
For each test case, 5 lines follow. Each line contains 2 real numbers  xi,yi(109xi,yi109) , denoting the coordinate of this point.
 

Output
Two numbers are equal if and only if the difference between them is less than  104
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
HDU 5563 Clarke and five-pointed star(判断正五边形)——BestCoder Round #62(div.1 div.2)_第1张图片 HDU 5563 Clarke and five-pointed star(判断正五边形)——BestCoder Round #62(div.1 div.2)_第2张图片
 

Source
BestCoder Round #62 (div.2)
 

/************************************************************************/

附上该题对应的中文题

Clarke and five-pointed star

 
 
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
克拉克是一名人格分裂患者。某一天克拉克分裂为一个几何学习者,在研究多边形。
在研究某一个多边形的时候,克拉克发现他多次遇到判断5个点是否能组成一个五角星的问题,在这里,这5个点分别代表五角星的五个顶点(顶角上的点)。于是他跑来想你求助,让你写出一个程序快速判定。即对于给出的5个点,判断这5个点是否能组成一个五角星。
输入描述
第一行一个整数T(1 \le T \le 10)T(1T10),表示数据的组数。
每组数据有55行,每行有两个实数x_i, y_i(-10^9 \le x_i, y_i \le 10^9)xi,yi(109xi,yi109),表示第ii个点的坐标。
输出描述
如果两个量相差小于10^{-4}104,则认为这两个量相等。
对于每组数据,如果这55个点能组成一个五角星,则输出YesYes,否则输出NoNo。(如果55个点相同,那么也能组成一个五角星。)
输入样例
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
输出样例
Yes
No
Hint
样例1如图
HDU 5563 Clarke and five-pointed star(判断正五边形)——BestCoder Round #62(div.1 div.2)_第3张图片

样例2如图
HDU 5563 Clarke and five-pointed star(判断正五边形)——BestCoder Round #62(div.1 div.2)_第4张图片
/****************************************************/

出题人的解题思路:

Clarke and five-pointed star

容易看出只需要判断这5个点是否在一个正五边形上。

因此我们枚举排列,然后依次判断即可。

判定方法是,五条相邻边相等,五条对角线相等。

当然题目给的精度问题,窝只能说,如果泥做法不复杂,精度足够好的话,是可以过的。毕竟题目说的小于10^{-4}104是指理论上的,所以理论上适用所有的数之间的比较。所以有人问我开方前和开方后,我只能说,哪个精度高用哪个....

当然你也可以先求出凸包然后再判相邻距离......

这题明面上是让你判断5个顶点能否构成五角星,但是考虑到五角星的顶点与其对应的正五边形的顶点一一对应,故此题就转化成了判断5个给定的顶点能否构成正五边形
然而并不会证明正五边形,所以把所有点两两之间的边都求出来,排序后,判等,又因为担心这样还不够,还多求了一下角度等于108°
另外,题目的精度要注意,  104 ,如果不控制精度,求边开方四舍五入后会造成误差
104104
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-4
using namespace std;
const int N = 5;
const int M = 100005;
const int inf = 100000000;
const int mod = 2009;
const double PI = acos(-1);
struct node
{
    double x,y;
}s[N];
double Abs(double x)
{
    if(x>0)
        return x;
    return -x;
}
double ans[2*N],z;
int main()
{
    int t,i,j,k;
    scanf("%d",&t);
    while(t--)
    {
        for(i=0;i<5;i++)
            scanf("%lf%lf",&s[i].x,&s[i].y);
        for(k=i=0;i<5;i++)
            for(j=0;j<i;j++)
                ans[k++]=sqrt((s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y));
        sort(ans,ans+10);//printf("%lf\n",PI);
        z=180*acos((ans[0]*ans[0]+ans[1]*ans[1]-ans[9]*ans[9])/ans[0]/ans[1]/2)/PI;//printf("%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",ans[0],ans[1],ans[2],ans[3],ans[4],ans[5],ans[6],ans[7],ans[8],ans[9],z);
        if(Abs(ans[0]-ans[1])<exp&&Abs(ans[1]-ans[2])<exp&&Abs(ans[2]-ans[3])<exp&&Abs(ans[3]-ans[4])<exp&&Abs(ans[4]-ans[5])>exp&&Abs(ans[5]-ans[6])<exp&&Abs(ans[6]-ans[7])<exp&&Abs(ans[7]-ans[8])<exp&&Abs(ans[8]-ans[9])<exp&&Abs(z-108)<exp)
            puts("Yes");
        else
            puts("No");
    }
    return 0;
}
菜鸟成长记

你可能感兴趣的:(ACM)