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): 1797    Accepted Submission(s): 1045


    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

    最后题目意思就是给你n个点,判断是否能组成正n边形。实际上由于正三角形正五边形,正六边形不可能都由整数点(即横坐标和纵坐标都是整数)构成,故我们只用判断能组成正方形即可。



    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<queue>
    #include<stack>
    #include<math.h>
    #include<vector>
    #include<map>
    #include<set>
    #include<stdlib.h>
    #include<cmath>
    #include<string>
    #include<algorithm>
    #include<iostream>
    using namespace std;
    struct point
    {
        int  x,y;
    } pp[110];
    int main()
    {
        int  t,i,j,n,k,cnt;
        int  s[6];
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            cnt=0;
            for(i=0; i<n; i++)
                scanf("%d%d",&pp[i].x,&pp[i].y);
            if(n!=4)
            {
                puts("NO");
                continue;
            }
            for(i=0; i<n; i++)
            {
                for(j=0; j<i; j++)
                {
                    s[cnt++]=(pp[i].x-pp[j].x)*(pp[i].x-pp[j].x)+(pp[i].y-pp[j].y)*(pp[i].y-pp[j].y);
                }
            }
    
     sort(s,s+6);
            if(s[0]==s[1]&&s[2]==s[1]&&s[2]==s[3]&&s[4]==s[5]&&s[4]!=s[3])
                puts("YES");
            else
                puts("NO");
        }
        return 0;
    }

  • 相关阅读:
    Mybatis中Log4j日志的使用
    Mybatis结果集ResultMap映射
    Mybatis中的基本对象的生命周期和作用域
    IAR瑞萨单片机开发加入printf调试函数
    【转】C语言mem.h中的函数介绍
    【转】c语言位域操作—_结构体内冒号:的使用
    串口数据传输当中的共用体和结构体转换
    【转】printf格式串中的%f的输出格式和内容
    【转】缓冲区设计--环形队列(C++)
    【转】环形队列理论(C语言)
  • 原文地址:https://www.cnblogs.com/hjch0708/p/7554826.html
Copyright © 2011-2022 走看看