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. mina 实例(转载)

    mina:http://mina.apache.org/ 原文:http://maosheng.iteye.com/blog/1891665 大并发量socket 通信框架MINA介绍 博客分类: J ...

  2. 向上取整Ceil,向下取整Floor,四舍五入Round

    几个数值函数的功能实现: (1)int Ceil(float f) int Ceil(float f) { int integer = (int)f; if (f > (float)intege ...

  3. java编辑器

    package editor; import java.io.*; import java.awt.*; import java.awt.datatransfer.Clipboard; import ...

  4. Docker和DevOps是找工作必备技能

    根据最近的IT Jobs Watch数据,涉及Docker技术的的工作角色上升了317名次,排在500个最受追捧的IT技能第二位.无独有偶,从Rackspace最近的研究表明,Docker和DevOp ...

  5. hdu 4545 魔法串 2013金山西山居创意游戏程序挑战赛——初赛(1)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4545 这题太坑了,小明的串可以任意删掉某个字符 这句话不知道大家是怎么理解的,我觉得应该是能够删除其中 ...

  6. Groovy在不同JDK版本下的性能差异

    Groovy作为一种动态语言,性能和JAVA比肯定是差不少,根据网友的测试,由于测试环境,场景和编译参数的不同,大概有差2到7倍的差距 那么同样的Groovy,在不同的JDK版本下,会有着怎样的差异呢 ...

  7. 10_Segue Example

    10 // // ViewController.swift // Segues Example // // Created by ZC on 16/1/10. // Copyright © 2016年 ...

  8. 吃透C#集合~大话目录

    最近买了一本<C#数据结构>的书,这种书确实少见,一般的数据结构都是采用C,C++来实现的,C#可以说是稀有了,呵呵,书写的不错,把C#的核心Collections介绍了一个透彻,对于我来 ...

  9. SDWebImage缓存

    缓存图片方法 [[SDImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey]; 读取缓存 UIImage *myCache ...

  10. border-radius 知识点

    border-radius:50px; 边框半径 CSS度量值都:em.px.百分比如果设置1个值,表示4个圆角都使用这个值.如果设置两个值,表示左上角和右下角使用第一个值,右上角和左下角使用第二个值 ...