题目链接: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. 【无聊放个模板系列】POJ 1274 (匈牙利)

    #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...

  2. 深入理解ClassLoader(四)—类的父委托加载机制

    上几次我们介绍到了JVM内部的几个类加载器,我们来重新画一下这个图,再来看一下他们之间的关系.

  3. log4jdbc-remix安装配置

    1.maven安装依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://w ...

  4. red5研究(一):下载,工程建立、oflaDemo安装、demo测试

    一.red5下载.添加工程到myeclipse 1,从官网上下载red51.01版本(我下载的是red51.0的版本),下载链接http://www.red5.org/downloads/red5/1 ...

  5. Qt之自定义控件(开关按钮)Qt之模拟时钟

    http://blog.csdn.net/u011012932/article/details/52164289 http://blog.csdn.net/u011012932/article/det ...

  6. Netty实现高性能RPC服务器

    在本人写的前一篇文章中,谈及有关如何利用Netty开发实现,高性能RPC服务器的一些设计思路.设计原理,以及具体的实现方案(具体参见:谈谈如何使用Netty开发实现高性能的RPC服务器).在文章的最后 ...

  7. lib库依赖解决

    当前环境之前是装过MySQL官方版本5.6.22,想测试Percona版本MySQL.启动Percona-MySQL报错. [root@dg7 support-files]# /etc/init.d/ ...

  8. Rabbitmq中rabbitmqctl的常用命令

    学习rabbitmq,原理之后第一个要掌握的就是rabbitmqctl这个命令的用法了,rabbitmq的管理功能最全的就是rabbitmqctl命令了,当然还有HTTP API和UI两种管理手段. ...

  9. android系统平台显示驱动开发简要:LCD常用接口篇『二』

    平台信息:内核:linux3.4.39系统:android4.4 平台:S5P4418(cortex a9) 作者:瘋耔(欢迎转载,请注明作者) 欢迎指正错误,共同学习.共同进步!! 关注博主新浪博客 ...

  10. Tomcat详解

    解压缩下载的Tomcat压缩包,呈现的目录结构如下. bin:目录存放一些启动和关闭Tomcat的可执行程序和相关内容.conf:存放关于Tomcat服务器的全局配置.lib:目录存放Tomcat运行 ...