题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5533

Dancing Stars on Me

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

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
 
题意:给你n个坐标让你判断是不是正n边形;
题解:从第一个点a开始,找这个点到其余所有点中距离最短的点b,然后将点a标记,再以b为起点找其余没有标记过的点中距离他最近的c,再将b点标记,以此类推,(注意将所有的最短边存下来)最后如果所有的最短边都相等则是正多边形
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
#define MAX 10010
#define INF 0x3f3f3f
#define DD double
using namespace std;
DD f(DD x1,DD y1,DD x2,DD y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
int t,n,m,j,i,k;
DD x[MAX],y[MAX];
DD s[MAX];
int vis[MAX];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%lf%lf",&x[i],&y[i]);
int k=0;
memset(vis,0,sizeof(vis));
DD Min;
int next=1;
int ans=1;
for(i=1;i<=n;i++)
{
Min=INF;
for(j=1;j<=n;j++)
{
if(next==j) continue;
//如果自己到自己就跳过
else if(!vis[j])
{
if(Min>f(x[next],y[next],x[j],y[j]))
{
Min=f(x[next],y[next],x[j],y[j]);
//找距离next点最近的点
ans=j;
}
}
}
next=ans; //找到下一个点
vis[next]=1;
s[k++]=Min;
}
int flag=1;
for(i=0;i<k-1;i++)
{
if(s[i]!=s[i+1])
{
flag=0;
break;
}
}
if(s[0]!=s[k-1])
flag=0;
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

  

hdu 5533 Dancing Stars on Me的更多相关文章

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

  2. 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 ...

  3. 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 ...

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

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

  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(判断正多边形)

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

  7. [hdu 6184 Counting Stars(三元环计数)

    hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...

  8. hdu 5533

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

  9. hdu 5533 正n边形判断 精度处理

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

随机推荐

  1. orm框架与缓存的关系

    1.mybatis规定,一级缓存没必要bean类实现序列化,但二级缓存bean类必须实现序列化. 因为二级缓存是基于namespace的也就是基于接口的,二级缓存可以设置存储源,可以是redis或者m ...

  2. C#操作xml文档,cuid,dategridview显示数据

    界面 //所有的数据全部在集合中             //dgv控件绑定List集合,List集合中有User类的对象,对象里有属性,把属性绑定到没列的数据上             dgv.Da ...

  3. 编程之美 3.1 字符串移位包含问 复杂度(O(N*K)

    分享关于编程之美3.1自己编写的代码,很简单. s2.沿着s1匹配(循环匹配,利用%Length技巧),匹配上,返回true. //BOP3.1 char src[] = "AABBCD&q ...

  4. windows下使用远程工具登录虚拟机上的Linux、访问虚拟机上的服务 、端口转发、win7 telnet登陆虚拟机

    首先要清楚virtual box如何设置端口转发: 一篇文章: 如何使用VirtualBox进行端口转发 由于默认的方式是用NAT来做虚拟机网络的,因此如果从外网想访问虚拟机的应用会比较麻烦.以前一直 ...

  5. window下gvim中文界面改变成英文界面

    中文环境下设置GVIM的界面.菜单.提示为英文语言 修改你的_vimrc,通常为类似C:\Program Files\Vim 加入以下语句至末尾 " set the menu & t ...

  6. python学习笔记四--元组

    一.元组: 1. 不可变更的列表 2. 从语法上,她们是编写在小括号里,不是方括号里,列表是编写在方括号里的 3. 圆括号也同时用于表达式,如果想说明这是一个元组,不是表达式,可以在value后,关闭 ...

  7. 锋利的JQuery-Jquery中的事件和动画

    有时候觉得这些内容都好简单,真想看看就算了. 事件绑定 bing(type [,data],fn) 第一个参数:事件类型包括:blur,focus,load,resize,scroll,unload, ...

  8. GB2312 简体中文编码表

    GB 2312中对所收汉字进行了“分区”处理,每区含有94个汉字/符号.这种表示方式也称为区位码. 01-09区为特殊符号. 16-55区为一级汉字,按拼音排序. 56-87区为二级汉字,按部首/笔画 ...

  9. Where is Vasya?

    Where is Vasya? Vasya stands in line with number of people p (including Vasya), but he doesn't know ...

  10. HTML5学习(十一)---服务器发送事件

    参考教程:http://www.w3school.com.cn/html5/html_5_serversentevents.asp HTML5 服务器发送事件(server-sent event)允许 ...