zoukankan      html  css  js  c++  java
  • 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
    ");
    31         }
    32         else{
    33             printf("NO
    ");
    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
    ");
    75         }
    76         else{
    77             printf("NO
    ");
    78         }
    79     }
    80     return 0;
    81 }
  • 相关阅读:
    python中不同文件中函数和类的调用
    python中使用queue实现约瑟夫环(约瑟夫问题)求解
    C语言中几个常用数学计算函数ceil(), floor(), round()的用法
    python中stack在实际中的简单应用之进制转换
    python中stack在实际中的简单应用之平衡符号
    python中两种栈实现方式的性能对比
    python实现stack并测试
    昨天的面试的一点思考
    从历代帝王的的创业经历看哪些人适合创业
    python chr()和ord()的含义和使用方法
  • 原文地址:https://www.cnblogs.com/tingtin/p/9629952.html
Copyright © 2011-2022 走看看