zoukankan      html  css  js  c++  java
  • 2015 ICPC亚洲区域赛长春站 G Dancing Stars on Me(几何+暴力)

    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.

    1≤T≤300
    3≤n≤100
    −10000≤xi,yi≤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

    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个点能否组成正n边形。

    思路:

    由于n的范围较小,所以可以直接暴力求解。因为正n边形上各点到其他点的最短距离即是该正n边形的边长w,所以只要判断下所有点之间的最短距离是否均为w即可!

    题目链接

    #include<bits/stdc++.h>
    #define MAX 100
    #define INF 0x3f3f3f3f
    using namespace std;
    int x[MAX+5],y[MAX+5],e[MAX+5][MAX+5];
    int dis(int a,int b)
    {
        return ((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
    }
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            memset(e,INF,sizeof(e));
            int n,i,j,sum=0;
            scanf("%d",&n);
            for(i=1;i<=n;i++)
                scanf("%d%d",&x[i],&y[i]);
            int minn=INF;
            for(i=1;i<=n;i++)
            {
                for(j=i+1;j<=n;j++)
                {
                    e[i][j]=dis(i,j);
                    minn=min(minn,e[i][j]);
                }
            }
            for(i=1;i<=n;i++)
                for(j=i+1;j<=n;j++)
                    if(minn==e[i][j])
                        sum++;
            if(sum==n) printf("YES
    ");
            else printf("NO
    ");
        }
        return 0;
    }
  • 相关阅读:
    20170421 F110 常见问题
    BAPI_ACC_DOCUMENT_POST 解决原因代码输入问题-利用BADI
    ABAP f4帮助输入多个值
    002 MIRO发票校验采购订单项目科目分配类别检查增强-20150819
    001infor record 计划时间取值增强-20150622
    003 F-47创建预付定金请求检查增强-20150819.docx
    整理开源协议问题 GPL APACHE
    拆我的跨界手环
    ThinkPHP 的一个神秘版本 ThinkPHP 1.2
    关于 Vue 方法前面的美元符号
  • 原文地址:https://www.cnblogs.com/kannyi/p/9873317.html
Copyright © 2011-2022 走看看