hdu 5533 Dancing Stars on Me
题目链接: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
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.
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
,y
i
, describe the coordinates of n
stars.
1≤T≤300
3≤n≤100
−10000≤xi
,y
i
≤10000
All coordinates are distinct.
can form a regular polygon. Otherwise, output "`NO`" (both without
quotes).
#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的更多相关文章
- 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 ...
- 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(数学,水)
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 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(判断正多边形)
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- [hdu 6184 Counting Stars(三元环计数)
hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...
- hdu 5533
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- hdu 5533 正n边形判断 精度处理
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
随机推荐
- 【无聊放个模板系列】POJ 1274 (匈牙利)
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 深入理解ClassLoader(四)—类的父委托加载机制
上几次我们介绍到了JVM内部的几个类加载器,我们来重新画一下这个图,再来看一下他们之间的关系.
- log4jdbc-remix安装配置
1.maven安装依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://w ...
- red5研究(一):下载,工程建立、oflaDemo安装、demo测试
一.red5下载.添加工程到myeclipse 1,从官网上下载red51.01版本(我下载的是red51.0的版本),下载链接http://www.red5.org/downloads/red5/1 ...
- Qt之自定义控件(开关按钮)Qt之模拟时钟
http://blog.csdn.net/u011012932/article/details/52164289 http://blog.csdn.net/u011012932/article/det ...
- Netty实现高性能RPC服务器
在本人写的前一篇文章中,谈及有关如何利用Netty开发实现,高性能RPC服务器的一些设计思路.设计原理,以及具体的实现方案(具体参见:谈谈如何使用Netty开发实现高性能的RPC服务器).在文章的最后 ...
- lib库依赖解决
当前环境之前是装过MySQL官方版本5.6.22,想测试Percona版本MySQL.启动Percona-MySQL报错. [root@dg7 support-files]# /etc/init.d/ ...
- Rabbitmq中rabbitmqctl的常用命令
学习rabbitmq,原理之后第一个要掌握的就是rabbitmqctl这个命令的用法了,rabbitmq的管理功能最全的就是rabbitmqctl命令了,当然还有HTTP API和UI两种管理手段. ...
- android系统平台显示驱动开发简要:LCD常用接口篇『二』
平台信息:内核:linux3.4.39系统:android4.4 平台:S5P4418(cortex a9) 作者:瘋耔(欢迎转载,请注明作者) 欢迎指正错误,共同学习.共同进步!! 关注博主新浪博客 ...
- Tomcat详解
解压缩下载的Tomcat压缩包,呈现的目录结构如下. bin:目录存放一些启动和关闭Tomcat的可执行程序和相关内容.conf:存放关于Tomcat服务器的全局配置.lib:目录存放Tomcat运行 ...