码迷,mamicode.com
首页 > 其他好文 > 详细

Clarke and five-pointed star

时间:2017-07-30 13:58:57      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:one   frame   data   ant   ons   -o   scan   can   data-   

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.

InputThe first line contains an integer T(1T10)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(?109xi,yi109)xi,yi(?109≤xi,yi≤109), denoting the coordinate of this point.
OutputTwo numbers are equal if and only if the difference between them is less than 10?410?4. 
For each test case, print YesYes if they can compose a five-pointed star. Otherwise, print NoNo. (If 5 points are the same, print YesYes. )
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技术分享技术分享

我想了下,感觉这道题做法很多啊,判边判点的,但是一想还是觉得判边比较轻松,只要考率里面五条边相等,外面五条边相等就好了

#include<bits/stdc++.h>
using namespace std;
int main() {
    int T,i,j;
    double x[5],y[5],a[15];
    scanf("%d",&T);
    while(T--) {
        for(i=0; i<5; i++)
            scanf("%lf%lf",&x[i],&y[i]);
        int t=0,f=1;
        for(i=0; i<5; i++)
        for(j=0; j<i; j++)
        a[t++]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
        sort(a,a+t);
        for(i=0; i<9; i++)
            if(i!=4&&fabs(a[i]-a[i+1])>0.0001) f=0;
        printf("%s\n",f?"Yes":"No");
    }
    return 0;
}

 

Clarke and five-pointed star

标签:one   frame   data   ant   ons   -o   scan   can   data-   

原文地址:http://www.cnblogs.com/BobHuang/p/7258735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!