hdu5533 Dancing Stars on Me (思维题)

题目地址

hdu5533

题目大意

给出n个点,问你能不能凑成一个正n边形。

解题思路

非常有意思的一个题。想要形成正n边形,两个点之间的距离必定是它周围的点之间的最短距离。那我们把每个点和其他边的距离存下来,查找到其中相等并且最短的边数量,如果等于n就能凑成正n边形。

AC代码

#include 
#include 
#include 

using namespace std;

struct node
{
     
	double x, y;
};

struct node p[110];
double a[10010];

int main()
{
     
	int t;
	
	cin >> t;
	
	while (t--)
	{
     
		int n, ans = 0;
		
		cin >> n;
		
		for (int i=0; i<n; i++)
			cin >> p[i].x >> p[i].y;
	
		for (int i=0; i<n; i++)
		{
     
			for (int j=i+1; j<n; j++)
			{
     
				a[ans++] = sqrt(pow(p[i].x - p[j].x, 2) + pow(p[i].y - p[j].y, 2));
			}
		}
		
		sort (a, a+ans);
		
		int num = 1;
		
		for (int i=1; i<n; i++)
		{
     
			if (a[i] == a[0])
			{
     
				num++;
			}
		}
		
		if (num >= n)
		{
     
			cout << "YES" << endl;
		}
		else
		{
     
			cout << "NO" << endl;
		}
	}
	
	return 0;
}

你可能感兴趣的:(练习题)