文章标题 HDU 5533 : Dancing Stars on Me

来源:互联网 发布:电路图制作软件cad 编辑:程序博客网 时间:2024/06/13 02:18

Dancing Stars on Me

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 indicating the total number of test cases. Each test case begins with an integer , denoting the number of stars in the sky. Following lines, each contains integers , describe the coordinates of stars.

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条边是所有两两的两个点的距离最短的。所以只要把n个点所有的两点之间的距离保存下来,看有没有n条最短的边。
代码:

#include<iostream>#include<string>#include<cstdio>#include<cstring>#include<vector>#include<math.h>#include<map>#include<queue> #include<algorithm>using namespace std;const int inf = 0x3f3f3f3f;struct node {    int x,y;};node a[105];int main (){    int t;    scanf ("%d",&t);    while (t--){        int n;        scanf ("%d",&n);        for (int i=0;i<n;i++){            scanf ("%d%d",&a[i].x,&a[i].y);        }        vector <long long>v;//保存两点距离        long long tmp;        for (int i=0;i<n;i++){遍历所有的两点            for (int j=i+1;j<n;j++){                long long xn=a[i].x-a[j].x;                long long yn=a[i].y-a[j].y;                tmp=xn*xn+yn*yn;                v.push_back(tmp);            }        }        sort (v.begin(),v.end());//排序        long long minx=v[0];        int len=upper_bound (v.begin(),v.end(),minx)-v.begin();//找第一个比最短距离大的下标,即最短距离的条数。        if (len==n){            printf ("YES\n");        }        else printf ("NO\n");    }    return 0;}
0 0
原创粉丝点击