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. ASP.NET MVC Controller向View传值方式总结

    Controller向View传值方式总结 总结发现ASP.NET MVC中Controller向View传值的方式共有6种,分别是: ViewBag ViewData TempData 向普通Vie ...

  2. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  3. .Net跨平台中遇到的问题小结

    一:创建MVC网站,需要修改Views视图文件夹下的Web.config 二:需要添加web.config中的 <system.web> <compilation debug=&qu ...

  4. MYSQL 的数据读取方式

    例子: create table T(X bit(8)); insert into T (X) values(b'11111111'); select X from T; 这个时候会发现这个X 是乱码 ...

  5. 4_Is Prime

    4 // // ViewController.swift // Is Prime // // Created by ZC on 16/1/9. // Copyright © 2016年 ZC. All ...

  6. Java常用类库--观察者设计模式( Observable类Observer接口)

    如果要想实现观察者模式,则必须依靠java.util包中提供的Observable类和Observer接口. import java.util.* ; class House extends Obse ...

  7. mysql 性别存储

    大家在设计数据库时,碰到 性别.状态等 这些 值比较固定的列时,数据类型 是如何定义? 通常都是采用 : 1 create table `XXX` 2 ( 3 ........ 4 sex int(1 ...

  8. android下tcpdump抓包

    tcpdump是最快捷方便的抓包方式,还可以加深对网络协议的理解.android下可以通过如下方式抓包: 1 Android上启动tcpdump Android设备可以把tcpdump的可执行文件上传 ...

  9. BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊(动态树)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2002 [题目大意] 给出一片森林,操作允许更改一个节点的父亲,查询一个节点的深度. [ ...

  10. Noip2013错误避免

    很多的时候,我们会说,这道题我会做,算法想出来了,但是这里那里少了一些判断,导致一分未得,或是说变量名错误,或者说干脆是文件名错误.这些都不是理由,如果火箭发射半空爆炸,可以说是控制器中一个运算符错误 ...