hdu 5563 Clarke and five-pointed star (水题)

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

 

 

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
 
 
 
 
 
 
遍历五个点,找到与当前点最远的点,求出距离。可以求得五个距离,如果这五个距离相等,则可以组成一个正五角星。
 
 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define PI acos(-1)

int cmp(const void *a, const void *b){
  return *(double *)a > *(double *)b ? 1 : -1;
}
int main(){
  int T;
  scanf("%d", &T);
  while(T--){
    double x[5], y[5];
    int i, j;
    int count = 0;
    double hehe, hoho;
    for(i = 0; i < 5; i++) scanf("%lf%lf", &x[i], &y[i]); //保存下五个点的数据
    for(i = 0; i < 5; i++){
      double dis[5]; //操作当前点
      for(j = 0; j < 5; j++){
        dis[j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
      }
    qsort(dis, 5, sizeof(double), cmp); //排序找到距离当前点最远的点
    double dismax;
    dismax = dis[4];
    if(count == 0) hehe = dismax;
    if(-0.0001 < hehe - dismax && hehe - dismax < 0.0001) count++;
    hehe = dismax;
    }

    if(count == 5) printf("Yes\n"); //五条边相等
    else printf("No\n");
  }
  return 0;
}

posted @ 2015-11-16 15:27  shadow_C  阅读(146)  评论(0编辑  收藏  举报