zoukankan      html  css  js  c++  java
  • 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


    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.

    1T300
    3n100
    10000xi,yi10000
    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
    ");
    		else
    		printf("NO
    ");
    	}
    	return 0;
    } 
    

      

  • 相关阅读:
    串口应用
    状态栏颜色
    冒泡排序
    快速排序
    good软件测试博客地址
    软件测试面试题
    股票基础知识
    软件测试基本知识
    软件测试流程
    mycat实现分库分表(二)
  • 原文地址:https://www.cnblogs.com/tonghao/p/5031025.html
Copyright © 2011-2022 走看看