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,yi
, describe the coordinates of n
stars.
1≤T≤300
3≤n≤100
−10000≤xi,yi≤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 ...
随机推荐
- CentOS系统内核升级
yum -y update 升级所有包,改变软件设置和系统设置,系统版本内核都升级 yum -y upgrade 升级所有包,不改变软件设置和系统设置,系统版本升级,内核不改变
- 【转】奇异值分解(We Recommend a Singular Value Decomposition)
文章转自:奇异值分解(We Recommend a Singular Value Decomposition) 文章写的浅显易懂,很有意思.但是没找到转载方式,所以复制了过来.一个是备忘,一个是分享给 ...
- ubuntu 解决依赖问题
安装aptitude包管理器 然后用aptitude安装 sudo aptitude install ***
- 使用dreamever去掉文件头部BOM(bom)信息 From 百度经验
本文来此百度经验: 地址为:http://jingyan.baidu.com/article/3f16e003c3dc172591c103e6.html OM主要处理浏览器窗口与框架,但事实上,浏览器 ...
- brew,gem,rvm 和 bundler软件包的管理工具
brew是OS X上提供软件包的管理.Homebrew将软件包安装到单独的目录,然后符号链接到/usr/local 中,完全基于git和ruby.使用gem来安装你的gems,用brew来搞定他们的依 ...
- grep 同时满足多个关键字和满足任意关键字
grep 同时满足多个关键字和满足任意关键字 ① grep -E "word1|word2|word3" file.txt 满足任意条件(word1.word2和word ...
- Java线程池的工作原理与实现
简单介绍 创建线程有两种方式:继承Thread或实现Runnable.Thread实现了Runnable接口,提供了一个空的run()方法,所以不论是继承Thread还是实现Runnable,都要有自 ...
- poj1989
一道非常神奇的题目 var v:array[0..10010] of boolean; n,k,i,x,ans,s:longint; begin readln(n,k); fillchar(v,siz ...
- UVa 11040 (水题) Add bricks in the wall
题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到 ...
- BZOJ_1027_[JSOI2007]_合金_(计算几何+Floyd求最小环)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1027 共三种金属,\(m\)种材料,给出每种材料中三种金属的占比. 给出\(n\)种合金的三种 ...