hdu 5533 简单几何

你的名字 2022-08-10 03:54 219阅读 0赞

Dancing Stars on Me

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 292 Accepted Submission(s): 188

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 indicating the total number of test cases. Each test case begins with an integer n, denoting the number of stars in the sky. Following n lines, each contains 2 integers x**i,y**i, describe the coordinates of n stars.

1≤T≤300
3≤n≤100
−10000≤x**i,y**i≤10000
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

Source

2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大)

题意:给定平面上的n个整数点,判断是不是能够构成正n边形;
分析:以前做过类似的题,地球人都知道只有正4边形才能由整点构成,所以只要判断是不是正4变形就行。

  1. #include<bitset>
  2. #include<map>
  3. #include<vector>
  4. #include<cstdio>
  5. #include<iostream>
  6. #include<cstring>
  7. #include<string>
  8. #include<algorithm>
  9. #include<cmath>
  10. #include<stack>
  11. #include<queue>
  12. #include<set>
  13. #define inf 0x3f3f3f3f
  14. #define mem(a,x) memset(a,x,sizeof(a))
  15. using namespace std;
  16. typedef long long ll;
  17. typedef pair<int,int> pii;
  18. inline int in()
  19. {
  20. int res=0;char c;
  21. while((c=getchar())<'0' || c>'9');
  22. while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
  23. return res;
  24. }
  25. const int N=1010;
  26. pii a[N];
  27. set<int> s;
  28. int main()
  29. {
  30. int T=in();
  31. while(T--)
  32. {
  33. int n=in();
  34. s.clear();
  35. for(int i=0;i<n;i++) scanf("%d%d",&a[i].first,&a[i].second);
  36. if(n!=4)
  37. {
  38. puts("NO");
  39. continue;
  40. }
  41. for(int i=0;i<n;i++)
  42. {
  43. for(int j=0;j<n;j++)
  44. {
  45. if(i==j)continue;
  46. int t=(a[i].first-a[j].first)*(a[i].first-a[j].first)
  47. +(a[i].second-a[j].second)*(a[i].second-a[j].second);
  48. s.insert(t);
  49. }
  50. }
  51. if(s.size()!=2)
  52. {
  53. puts("NO");
  54. }
  55. else
  56. {
  57. if(*s.begin() * 2 == *(--s.end()))
  58. {
  59. puts("YES");
  60. }
  61. else puts("NO");
  62. }
  63. }
  64. return 0;
  65. }

发表评论

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

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

相关阅读

    相关 HDU - 1174(计算几何)

    问题描述: gameboy是一个CS高手,他最喜欢的就是扮演警察,手持M4爆土匪的头。也许这里有人没玩过CS,有必要介绍一下“爆头”这个术语:所谓爆头,就是子弹直接命中对方的