您的位置:首页 > 其它

HDU 5533 Dancing Stars on Me [数学]

2016-02-28 18:50 239 查看
2015区域赛 长春赛区 G题

Description

给N个格点,问能否组成正多边形

Algorithm

格点正多边形形只能是正方形

格点 百度百科

既然如此,N != 4就直接再见

然后6条边长度必定是4条相等,另外两条根号2,排序,判断一下就是了

Code

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
struct P
{
int x, y;
};
double dist(const P &a, const P &b)
{
return pow(a.x - b.x, 2)  + pow(a.y - b.y, 2);
}
bool solve()
{
int n;
scanf("%d", &n);
if (n != 4)
{
int x, y;
for (int i = 0;i < n; i++)
scanf("%d%d", &x, &y);
return false;
}
P a[4];
for (int i = 0; i < n; i++)
scanf("%d%d", &a[i].x, &a[i].y);
double d[6];
int k = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < i; j++)
d[k++] = dist(a[i], a[j]);
sort(d, d+k);
if (d[0] == d[1] && d[1] == d[2] && d[2] == d[3] &&
d[4] == d[5] && d[4] == d[3] * 2) return true;
return false;
}
int main()
{
int t = 1;
scanf("%d", &t);
for (int i = 0; i < t; i++)
solve() ? puts("YES") : puts("NO");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: