Dancing Stars on Me

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

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
 

题意:给你一个多边形,问你这个多边形是否是正多边形。。。

题解:无奈啊,我刚开始就判断边是否相等,用差集排序,相邻判断,果断wa,又想着没考虑角度,就想着对相邻两个边求差集,是否相等,各种wa,无耐加心碎啊,然后就暴力了了。。。就判断个相等边都要大于等于2,然后就对了。。。fuck。。。

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
#define T_T while(T--)
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=210;
int N;
struct Node{
LL x,y;
/*Node(LL x=0,LL y=0):x(x),y(y){}*/
};
Node dt[MAXN];
/*LL cross(Node a,Node b){
return a.x*b.y-a.y*b.x;
} int cmp(Node a,Node b){
if(cross(a,b)>=0)return 1;
else return 0;
}*/
/*
Node operator - (Node a,Node b){
return Node(a.x-b.x,a.y-b.y);
}*/
double getl(Node a,Node b){
LL x=a.x-b.x,y=a.y-b.y;
return sqrt(1.0*x*x+1.0*y*y);
}
bool judge(){
//double temp=getl(dt[0],dt[N-1]);
double ans;
for(int i=0;i<N;i++){
// if(temp!=getl(dt[i],dt[i-1]))return false;
double temp=INF;
int cnt=0;
for(int j=0;j<N;j++){
if(i==j)continue;
if(getl(dt[i],dt[j])<temp)temp=getl(dt[i],dt[j]);
if(i&&ans==temp)cnt++;
}
if(!i)ans=temp;
//printf("%lf %d\n",ans,cnt);
if(i)if(temp!=ans||cnt<2)return false;
} /*double x=cross(dt[0]-dt[N-1],dt[0]-dt[1]);
for(int i=1;i<N-1;i++){
int y;
if(x!=(y=cross(dt[i]-dt[i-1],dt[i]-dt[i+1]))){
return false;
}
}
if(x!=cross(dt[N-1]-dt[N-2],dt[N-1]-dt[0]))return false;*/
return true;
}
int main(){
int T;
SI(T);
T_T{
SI(N);
for(int i=0;i<N;i++)SL(dt[i].x),SL(dt[i].y);
//sort(dt,dt+N,cmp);
//for(int i=1;i<N;i++)printf("%d\n",cross(dt[i],dt[i-1]));
if(judge())puts("YES");
else puts("NO");
}
return 0;
}

  

Dancing Stars on Me(判断正多边形)的更多相关文章

  1. 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/Ot ...

  2. hdu 5533 Dancing Stars on Me 水题

    Dancing Stars on Me Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  3. hdu 5533 Dancing Stars on Me

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5533 Dancing Stars on Me Time Limit: 2000/1000 MS (Ja ...

  4. Dancing Stars on Me

    Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  5. HDU 5533/ 2015长春区域 G.Dancing Stars on Me 暴力

    Dancing Stars on Me Problem Description The sky was brushed clean by the wind and the stars were col ...

  6. Dancing Stars on Me---hdu5533(判断是否为正多边形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5533 题意:平面图中 有n个点给你每个点的坐标,判断是否能通过某种连线使得这些点所组成的n边形为 正n ...

  7. hdu 5533 Dancing Stars on Me(数学,水)

    Problem Description The sky was brushed clean by the wind and the stars were cold in a black sky. Wh ...

  8. 【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. Wh ...

  9. HDU 5533 Dancing Stars on Me( 有趣的计算几何 )

    链接:传送门 题意:给出 n 个点,判断能不能构成一个正 n 边形,这 n 个点坐标是整数 思路:这道题关键就在与这 n 个点坐标是正整数!!!可以简单的分析,如果 n != 4,那一定就不能构成正 ...

随机推荐

  1. 最小生成树Jungle Roads

    这道题一定要注意录入方式,我用的解法是prime算法 因为单个字符的录入会涉及到缓冲区遗留的空格问题,我原本是采用c语言的输入方法录入数据的,结果对了,但是提交却一直wrong,后来改成了c++的ci ...

  2. 今年暑假不AC1

    Description "今年暑假不AC?"  "是的."  "那你干什么呢?"  "看世界杯呀,笨蛋!"  " ...

  3. BZOJ 1935: [Shoi2007]Tree 园丁的烦恼( 差分 + 离散化 + 树状数组 )

    假如矩阵范围小一点就可以直接用二维树状数组维护. 这道题,  差分答案, 然后一维排序, 另一维离散化然后树状数组维护就OK了. ----------------------------------- ...

  4. C++学习之友元类和友元函数

    C++学习之友元类和友元函数       模板类声明也可以有友元,模板的友元可以分为以下几类:        1.非模板友元:        2.约束模板友元,即就是友元的类型取决于类被实例化的时候的 ...

  5. 高级PHP工程师所应该具备一些技能

          很多面试,很多人员能力要求都有"PHP高级工程师的字眼",如果您真心喜欢PHP,并且您刚起步,那么我简单说说一个PHP高级工程师所应该具备的,希望给初级或已经达到中级的 ...

  6. bzoj 1066 : [SCOI2007]蜥蜴 网络流

    题目链接 给一个n*m的图, 里面每一个点代表一个石柱, 石柱有一个高度. 初始时有些石柱上面有蜥蜴, 蜥蜴可以跳到距离他曼哈顿距离小于等于d的任意一个石柱上,跳完后, 他原来所在的石柱高度会减一, ...

  7. android-通知Notification

    发送通知 public class MyActivity extends Activity { @Override protected void onCreate(Bundle savedInstan ...

  8. 苹果iPhone不能判断红外发射管的好坏

    用手机来检测红外发射管好坏是目前比较常用的方法.实际操作比较简单,就是按照红外发射管的工作电压给发射管接上电源后,把手机的摄像头对着红外发射管就能看出好坏了.由于红外线是肉眼看不见的,如果不通过手机摄 ...

  9. spring+hibernate删除单条记录的几种方法

    spring+hibernate删除单条记录的几种方法

  10. 解决phpmyadmin-1800秒超时链接失效问题

    在phpmyadmin的配置文件里 \usr\share\phpMyAdmin\libraries\config.default.php 修改 $cfg[‘LoginCookieValidity’] ...