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;
    }

  • 相关阅读:
    Android屏幕适配
    设计模式学习心得
    C语言中的作用域、链接属性与存储属性
    二级指针删除单向链表
    C++编程风格
    python中index、slice与slice assignment用法
    lua_pcall与lua_call之间的区别
    lua-C++ userdata使用
    lua中调用C++函数
    C++中为什么有时要使用extern "C"
  • 原文地址:https://www.cnblogs.com/hjch0708/p/7554826.html
Copyright © 2011-2022 走看看