2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me

时间:2023-03-08 20:02:41

Dancing Stars on Me

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 186    Accepted Submission(s): 124

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 n lines, 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
Source
题意:问一个多边形是不是正多边形。。。
分析:极角排序后暴力判断就好。。。
正多边形相邻的三个点组成的三角形面积一定相等,且这三个点之间的两条线段长度相等
 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define MLL (1000000000000000001LL)
#define INF (1000000001)
#define For(i, s, t) for(int i = (s); i <= (t); i ++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i --)
#define Rep(i, n) for(int i = (0); i < (n); i ++)
#define Repn(i, n) for(int i = (n)-1; i >= (0); i --)
#define mk make_pair
#define ft first
#define sd second
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define sz(x) ((int) (x).size())
inline void SetIO(string Name)
{
string Input = Name + ".in";
string Output = Name + ".out";
freopen(Input.c_str(), "r", stdin);
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
char ch = ' ';
int Ret = ;
bool Flag = ;
while(!(ch >= '' && ch <= ''))
{
if(ch == '-') Flag ^= ;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
Ret = Ret * + ch - '';
ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
struct Point
{
int x, y;
} Arr[N];
int n; inline void Solve(); inline void Input()
{
int TestNumber = Getint();
while(TestNumber--)
{
n = Getint();
For(i, , n)
{
Arr[i].x = Getint();
Arr[i].y = Getint();
}
Solve();
}
} inline LL Sqr(int x) {
return 1LL * x * x;
} inline int Multi(const Point &O, const Point &A, const Point &B)
{
int X1 = A.x - O.x, X2 = B.x - O.x, Y1 = A.y - O.y, Y2 = B.y - O.y;
return X1 * Y2 - X2 * Y1;
} inline LL GetDist(const Point &A, const Point &B)
{
return Sqr(B.x - A.x) + Sqr(B.y - A.y);
} inline bool Compare(const Point &A, const Point &B)
{
int Det = Multi(Arr[], A, B);
if(Det) return Det > ;
LL Dist1 = GetDist(Arr[], A), Dist2 = GetDist(Arr[], B);
return Dist1 < Dist2;
} inline void Solve()
{
For(i, , n)
if(Arr[i].x < Arr[].x || (Arr[i].x == Arr[].x && Arr[i].y < Arr[].y))
swap(Arr[i], Arr[]);
sort(Arr + , Arr + + n, Compare); Arr[n + ] = Arr[], Arr[n + ] = Arr[];
bool Flag = ;
int Tmp, Dist;
For(i, , n)
{
int Det = Multi(Arr[i], Arr[i + ], Arr[i + ]);
LL Dist1 = GetDist(Arr[i], Arr[i + ]);
LL Dist2 = GetDist(Arr[i + ], Arr[i + ]);
if(Det <= || Dist1 != Dist2)
{
puts("NO");
return ;
}
if(Flag)
{
if(Tmp != Det || Dist1 != Dist)
{
puts("NO");
return ;
}
}
else Flag = , Tmp = Det, Dist = Dist1;
}
puts("YES");
} int main()
{
Input();
//Solve();
return ;
}