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): 592 Accepted Submission(s): 315
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.
1≤T≤300 3≤n≤100 −10000≤xi,yi≤10000 All coordinates are distinct.
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
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(判断正多边形)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Dancing Stars on Me
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 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 ...
- Dancing Stars on Me---hdu5533(判断是否为正多边形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5533 题意:平面图中 有n个点给你每个点的坐标,判断是否能通过某种连线使得这些点所组成的n边形为 正n ...
- 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 ...
- 【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 ...
- HDU 5533 Dancing Stars on Me( 有趣的计算几何 )
链接:传送门 题意:给出 n 个点,判断能不能构成一个正 n 边形,这 n 个点坐标是整数 思路:这道题关键就在与这 n 个点坐标是正整数!!!可以简单的分析,如果 n != 4,那一定就不能构成正 ...
随机推荐
- HDU 5573 Binary Tree(找规律)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5573 题意:给你一个完全二叉树,节点为自然数的排列(第一行1,第二行2 3,第三行4 5 6 7... ...
- ROS服务的理解
服务是节点之间通信的另一种方式,服务允许节点发起一个请求和接收一个响应. 打开终端在里面输入: roscore 查看当前的运行节点: rosnode list 返回结果: /rosout 查看当前的运 ...
- less 工具
less 工具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大.less 的用法比起 more 更加的有弹性.在 more 的时候,我们并没有办法向前面翻 ...
- PHP查询MYSQL表的主键
$sql = "SELECT * from Person"; $result = mysql_query($sql,$con); while ($property = mysql_ ...
- symfony2-不同bundle的entity的一对多关系
重点:其实和普通一个bundle中一样,只是把entity地址写全就行. 例子: 表commentone (多方) 表shopone(一方) 在Userbundle中的Commentone实体对应关系
- PCRE兼容正则表达式函数
1.preg_grep()函数 函数语法: array preg_grep ( string pattern, array input ) 函数功能: 使用数组input中的元素一一匹配表达式patt ...
- pl sql 无法解析指定的连接标识符
使用PLSQL Developer时,“ORA-12154: TNS:无法解析指定的连接标识符”问题的一个解决办法< xmlnamespace prefix ="o" ...
- bean 与 map 互转.
package com.sprucetec.tms.distribute.utils;import java.beans.BeanInfo;import java.beans.Introspectio ...
- BZOJ 4259 残缺的字符串(FFT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4259 [题目大意] 给出两个包含*和小写字母的字符串,*为适配符,可以和任何字符匹配, ...
- Foundation 框架 归档
一.使用XML属性列表归档 此方法适用于NSString.NSDictionary.NSarray.NSDate.NSnumber,其中atomically参数表示先将字典写入临时备份文件,成功之后, ...