杭电-5533Dancing Stars on Me

约定不等于承诺〃 2022-08-18 02:38 60阅读 0赞

Dancing Stars on Me

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

Total Submission(s): 583 Accepted Submission(s): 309

Problem Description

The sky was brushed clean by the wind and the stars were cold in a black sky. What a wonderful night. You observed that, sometimes the stars can form a regular polygon in the sky if we connect them properly. You want to record these moments by your smart camera. Of course, you cannot stay awake all night for capturing. So you decide to write a program running on the smart camera to check whether the stars can form a regular polygon and capture these moments automatically.

Formally, a regular polygon is a convex polygon whose angles are all equal and all its sides have the same length. The area of a regular polygon must be nonzero. We say the stars can form a regular polygon if they are exactly the vertices of some regular polygon. To simplify the problem, we project the sky to a two-dimensional plane here, and you just need to check whether the stars can form a regular polygon in this plane.

Input

The first line contains a integer T![Image 1][] indicating the total number of test cases. Each test case begins with an integer n![Image 1][], denoting the number of stars in the sky. Following n![Image 1][] lines, each contains 2![Image 1][] integers x![Image 1][]i![Image 1][],y![Image 1][]i![Image 1][]![Image 1][], describe the coordinates of n![Image 1][] stars.

1≤T≤300![Image 1][]
3≤n≤100![Image 1][]
−10000≤x![Image 1][]i![Image 1][],y![Image 1][]i![Image 1][]≤10000![Image 1][]
All coordinates are distinct.

Output

For each test case, please output “`YES`“ if the stars can form a regular polygon. Otherwise, output “`NO`“ (both without quotes).

Sample Input

  1. 3
  2. 3
  3. 0 0
  4. 1 1
  5. 1 0
  6. 4
  7. 0 0
  8. 0 1
  9. 1 0
  10. 1 1
  11. 5
  12. 0 0
  13. 0 1
  14. 0 2
  15. 2 2
  16. 2 0

Sample Output

  1. NO
  2. YES
  3. NO

找出每个点离其他点的距离,然后排序,如果这些点能构成正多边形,那么最短的两条距离应该相等,而且要全部相等,才能构成一个正多边形!但是只要有一个不想等,就不能构成!

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<algorithm>
  5. using namespace std;
  6. double so(double x1,double y1,double x2,double y2)
  7. {
  8. return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  9. }
  10. int main()
  11. {
  12. double a,b,c,d,x[110],y[110],dis[1100];
  13. int i,j,m,n,flag;
  14. scanf("%d",&m);
  15. while(m--)
  16. {
  17. flag=0;
  18. scanf("%d",&n);
  19. for(i=0;i<n;i++)
  20. scanf("%lf%lf",&x[i],&y[i]);
  21. for(i=0;i<n;i++)
  22. {
  23. int t=0;
  24. for(j=0;j<n;j++)
  25. {
  26. if(j!=i)
  27. dis[t++]=so(x[i],y[i],x[j],y[j]);
  28. }
  29. sort(dis,dis+t);
  30. if(dis[0]!=dis[1])
  31. flag=1;
  32. }
  33. if(flag)
  34. printf("NO\n");
  35. else
  36. printf("YES\n");
  37. }
  38. return 0;
  39. }

[Image 1]:

发表评论

表情:
评论列表 (有 0 条评论,60人围观)

还没有评论,来说两句吧...

相关阅读

    相关 2075

    此题真的是简单的再不能简单了!呵呵!我一直纠结,出这样的题是什么意思呢?不懂!哎,不说那些废话了,直接 ac吧!呵呵! \include<iostream> using

    相关 2078

    说实话,此题是一道有严重bug的问题,对于xhd没晚能复习的科目数m根本就没用上!!!哎不管那么些了,反正ac了!呵呵!此题这样想xhd得复习效率是前一课程和后一课程复习效率差

    相关 2090

    此题就是一道令人无法琢磨的题!哎!!我简直就无语了!!呵呵!竟然能出这题。。。。 废话少说,直接ac!!! \\\ 此题要想输出结果,还需要注意一下! 在linux