首页 > 其他 > 详细

hdu 5533 Dancing Stars on Me

时间:2015-12-08 22:04:30      阅读:268      评论:0      收藏:0      [点我收藏+]

题目链接: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 x技术分享i技术分享,y技术分享i技术分享技术分享 , describe the coordinates of n技术分享 stars.

1T300技术分享
3n100技术分享
10000x技术分享i技术分享,y技术分享i技术分享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

原文:http://www.cnblogs.com/tonghao/p/5031025.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!