HDOJ 5563 Clarke and five-pointed star

Clarke and five-pointed star

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 865    Accepted Submission(s): 454


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
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:  5932 5931 5930 5929 5928 
 

     題意就是你5個頂點,判斷這五個頂點是否能組成五角星;

    一個判斷就是這五個點與其他四個點的距離是相等的,依次計算然後判斷就行了,這裏要注意的就是精度問題,如果兩個量相差小於10的-4次方,則認爲這兩個量相等。

   所以判斷的時候要注意精度。

#include<stdio.h>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
using namespace std;
struct p
{
    double x;
    double y;
    double len[4];
}a[5];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<5;i++)
            scanf("%lf%lf",&a[i].x,&a[i].y);
        for(int i=0;i<5;i++)
        {
            int l=0;
           for(int j=0;j<5;j++)
           {
               if(i==j)
                continue;
               a[i].len[l++]=sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
           }
        }
        for(int i=0;i<5;i++)
            sort(a[i].len,a[i].len+4);
        int f=0;
        for(int i=0;i<5;i++)
        {
            for(int j=0;j<5;j++)
            {
                for(int k=0;k<4;k++)
                {
                    if((a[i].len[k]-a[j].len[k])>0.00001)
                    {
                        printf("No\n");
                        f=1;
                        break;
                    }
                }
                if(f==1)
                    break;
            }
            if(f==1)
                break;
        }
        if(f==1)
            continue;
        printf("Yes\n");
    }
return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章