HDU 5533 Dancing Stars on Me [数学]

来源:互联网 发布:抽风解说 知乎 编辑:程序博客网 时间:2024/05/20 02:30

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;}
0 0
原创粉丝点击