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

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

2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大)

题意:问一个多边形是不是正多边形。。。

分析:极角排序后暴力判断就好。。。

正多边形相邻的三个点组成的三角形面积一定相等,且这三个点之间的两条线段长度相等

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <cstdlib>
  4 #include <cmath>
  5 #include <ctime>
  6 #include <iostream>
  7 #include <map>
  8 #include <set>
  9 #include <algorithm>
 10 #include <vector>
 11 #include <deque>
 12 #include <queue>
 13 #include <stack>
 14 using namespace std;
 15 typedef long long LL;
 16 typedef double DB;
 17 #define MIT (2147483647)
 18 #define MLL (1000000000000000001LL)
 19 #define INF (1000000001)
 20 #define For(i, s, t) for(int i = (s); i <= (t); i ++)
 21 #define Ford(i, s, t) for(int i = (s); i >= (t); i --)
 22 #define Rep(i, n) for(int i = (0); i < (n); i ++)
 23 #define Repn(i, n) for(int i = (n)-1; i >= (0); i --)
 24 #define mk make_pair
 25 #define ft first
 26 #define sd second
 27 #define puf push_front
 28 #define pub push_back
 29 #define pof pop_front
 30 #define pob pop_back
 31 #define sz(x) ((int) (x).size())
 32 inline void SetIO(string Name)
 33 {
 34     string Input = Name + ".in";
 35     string Output = Name + ".out";
 36     freopen(Input.c_str(), "r", stdin);
 37     freopen(Output.c_str(), "w", stdout);
 38 }
 39
 40 inline int Getint()
 41 {
 42     char ch = ‘ ‘;
 43     int Ret = 0;
 44     bool Flag = 0;
 45     while(!(ch >= ‘0‘ && ch <= ‘9‘))
 46     {
 47         if(ch == ‘-‘) Flag ^= 1;
 48         ch = getchar();
 49     }
 50     while(ch >= ‘0‘ && ch <= ‘9‘)
 51     {
 52         Ret = Ret * 10 + ch - ‘0‘;
 53         ch = getchar();
 54     }
 55     return Flag ? -Ret : Ret;
 56 }
 57
 58 const int N = 110;
 59 struct Point
 60 {
 61     int x, y;
 62 } Arr[N];
 63 int n;
 64
 65 inline void Solve();
 66
 67 inline void Input()
 68 {
 69     int TestNumber = Getint();
 70     while(TestNumber--)
 71     {
 72         n = Getint();
 73         For(i, 1, n)
 74         {
 75             Arr[i].x = Getint();
 76             Arr[i].y = Getint();
 77         }
 78         Solve();
 79     }
 80 }
 81
 82 inline LL Sqr(int x) {
 83     return 1LL * x * x;
 84 }
 85
 86 inline int Multi(const Point &O, const Point &A, const Point &B)
 87 {
 88     int X1 = A.x - O.x, X2 = B.x - O.x, Y1 = A.y - O.y, Y2 = B.y - O.y;
 89     return X1 * Y2 - X2 * Y1;
 90 }
 91
 92 inline LL GetDist(const Point &A, const Point &B)
 93 {
 94     return Sqr(B.x - A.x) + Sqr(B.y - A.y);
 95 }
 96
 97 inline bool Compare(const Point &A, const Point &B)
 98 {
 99     int Det = Multi(Arr[1], A, B);
100     if(Det) return Det > 0;
101     LL Dist1 = GetDist(Arr[1], A), Dist2 = GetDist(Arr[1], B);
102     return Dist1 < Dist2;
103 }
104
105 inline void Solve()
106 {
107     For(i, 2, n)
108         if(Arr[i].x < Arr[1].x || (Arr[i].x == Arr[1].x && Arr[i].y < Arr[1].y))
109             swap(Arr[i], Arr[1]);
110     sort(Arr + 2, Arr + 1 + n, Compare);
111
112     Arr[n + 1] = Arr[1], Arr[n + 2] = Arr[2];
113     bool Flag = 0;
114     int Tmp, Dist;
115     For(i, 1, n)
116     {
117         int Det = Multi(Arr[i], Arr[i + 1], Arr[i + 2]);
118         LL Dist1 = GetDist(Arr[i], Arr[i + 1]);
119         LL Dist2 = GetDist(Arr[i + 1], Arr[i + 2]);
120         if(Det <= 0 || Dist1 != Dist2)
121         {
122             puts("NO");
123             return ;
124         }
125         if(Flag)
126         {
127             if(Tmp != Det || Dist1 != Dist)
128             {
129                 puts("NO");
130                 return ;
131             }
132         }
133         else Flag = 1, Tmp = Det, Dist = Dist1;
134     }
135     puts("YES");
136 }
137
138 int main()
139 {
140     Input();
141     //Solve();
142     return 0;
143 }

时间: 2024-12-20 06:29:59

2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me的相关文章

2015ACM/ICPC亚洲区长春站 G hdu 5534 Partial Tree

Partial Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 228    Accepted Submission(s): 138 Problem Description In mathematics, and more specifically in graph theory, a tree is an undirect

2015ACM/ICPC亚洲区长春站 F hdu 5533 Almost Sorted Array

Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 447    Accepted Submission(s): 201 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort,

2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b

Count a * b Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 211    Accepted Submission(s): 116 Problem Description Marry likes to count the number of ways to choose two non-negative integers a

2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building

House Building Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 145    Accepted Submission(s): 123 Problem Description Have you ever played the video game Minecraft? This game has been one of t

2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory

Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 368    Accepted Submission(s): 202 Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips

2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich

Too Rich Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 245    Accepted Submission(s): 76 Problem Description You are a rich person, and you think your wallet is too heavy and full now. So yo

2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild

Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 446    Accepted Submission(s): 113 Problem Description Archaeologists find ruins of Ancient ACM Civilization, and they want to rebuild i

HDU 5533 Dancing Stars on Me 计算几何瞎暴力

Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1184    Accepted Submission(s): 651 Problem Description The sky was brushed clean by the wind and the stars were cold in a b

【hdu 5536】【 2015ACM/ICPC亚洲区长春站 】Chip Factory 题意&题解&代码

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意: 给定n个个数s1, s2- sn,求最大的(si+sj)^sk且满足(i!=j!=k). 题解: 很明显的一道字典树题目,把每个数都插入字典树,枚举两个数的和.考虑到可能会有重复的数,每次枚举到i,j时首先在字典树上删除 si 和 sj 然后再查询 si+sj . 代码: #include<iostream> #include<algorithm> #include&l