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 ;
}

最新文章

  1. C#和ASP.NET之事件
  2. JAVA多线程实现的三种方式
  3. [游戏模版1] MFC最小框架(base function including)
  4. Unity3D Android手机开发环境配置,可真机发布调试
  5. Tomcat报java.lang.ClassNotFoundException: 1catalina.org.apache.juli.FileHandler
  6. javascript-XMLHttpRequest
  7. AsyncSocket的使用
  8. Python学习入门基础教程(learning Python)--5.7 Python文件数据记录存储与处理
  9. 抛弃jQuery,拥抱原生JavaScript
  10. Trusted Execution Technology (TXT) --- 基本原理篇
  11. .NET Core 迁移躺坑记
  12. vue-百度地图-maker文字标签显示隐藏
  13. 【EF6学习笔记】(一)Code First 方式生成数据库及初始化数据库实际操作
  14. C# Lambda 表达式学习之(四):动态构建类似于 c =&gt; c.Age == 2 || c.Age == 5 || c =&gt; c.Age == 17 等等一个或多个 OrElse 的表达式
  15. mysql 查询优化 ~ select count 知多少
  16. latex学习(二)
  17. 结构体中string成员的问题
  18. java 父类引用指向子类对象---动态绑定
  19. ASP.net-空白页的问题
  20. 更新Python以及随后的nose,easy_install,pip,numpy,scipy和theano

热门文章

  1. CSS 实现垂直居中的几种方案
  2. git clone报错
  3. HDU 1978 记忆化搜索(dfs+dp)
  4. hrb 2134 素数
  5. Linux多线程编程——多线程与线程同步
  6. 使用eclipse开发Java web应用
  7. DP:Multiplication Puzzle(POJ 1651)
  8. HDU1712周期
  9. Maven简介
  10. p364习题1