hdu 5533

Dancing Stars on Me

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


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 nlines, each contains 2 integers xi,yi, describe the coordinates of n stars.

1T300
3n100
10000xi,yi10000
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
3 3 0 0 1 1 1 0 4 0 0 0 1 1 0 1 1 5 0 0 0 1 0 2 2 2 2 0
 

 

Sample Output
NO YES NO
 

 

Source
 

 

Recommend
 
 
复制代码
 1 #define  N  109
 2 int  t,n;
 3 double  x[N],y[N];
 4 double x_,y_;
 5 double  dis(double x,double y){
 6     return  sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_));
 7 }
 8 int main()
 9 {
10     scanf("%d",&t);
11     while(t--)
12     {
13         scanf("%d",&n);
14         x_=0,y_=0;
15         for(int i=0;i<n;i++){
16             scanf("%lf%lf",&x[i],&y[i]);
17             x_+=x[i]/n;
18             y_+=y[i]/n;
19         }
20         double temp=dis(x[0],y[0]);
21         int flag=1;
22         for(int i=1;i<n;i++)
23         {
24             if(dis(x[i],y[i])!=temp){
25                 flag=0;
26                 break;
27             }
28         }
29         if(flag){
30             printf("YES\n");
31         }
32         else{
33             printf("NO\n");
34         }
35     }
36     return 0;
37 }
38 
39 
40 
41 
42 
43 
44 //结论 在平面内,如果坐标都为整数,那么只有可能是正四边形
45 //1 1 1 1 2 2(排序后边长比例)
46 int x[N],y[N];
47 int a[10];
48 bool check()
49 {
50     if(n!=4)  return false;
51     int cnt=0;
52     for(int  i=0;i<4;i++)
53     {
54         for(int  j=i+1;j<4;j++)
55         {
56             a[cnt++]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
57         }
58     }
59     sort(a,a+cnt);
60     if(a[1]==a[0]&&a[2]==a[1]&&a[3]==a[2]&&a[4]==2*a[3]&&a[5]==a[4])
61         return true;
62     return false;
63 }
64 int main()
65 {
66     scanf("%d",&t);
67     while(t--)
68     {
69         scanf("%d",&n);
70         for(int  i=0;i<n;i++){
71             scanf("%d%d",&x[i],&y[i]);
72         }
73         if(check()){
74             printf("YES\n");
75         }
76         else{
77             printf("NO\n");
78         }
79     }
80     return 0;
81 }
复制代码

 

posted on   cltt  阅读(152)  评论(0编辑  收藏  举报

编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示