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;
    }
  • 相关阅读:
    【做题】51NOD1518 稳定多米诺覆盖——容斥&dp
    【做题】TCSRM592 Div1 500 LittleElephantAndPermutationDiv1——计数&dp
    【做题】TCSRM591 Div1 500 PyramidSequences——数形结合&思维
    【做题】NOWCODER142A Ternary String——数列&欧拉定理
    【做题】CF196E. Opening Portals 排除无用边&最小生成树
    【做题】HDU6331 Walking Plan——矩阵&分块
    【做题】BZOJ2534 L-gap字符串——调和级数
    【做题】BZOJ2342 双倍回文——马拉车&并查集
    overleaf 提交arXiv 不成功
    神经网络 (2)- Alexnet Training on MNIST
  • 原文地址:https://www.cnblogs.com/kannyi/p/9873317.html
Copyright © 2011-2022 走看看