您的位置:首页 > 其它

HDU 5533 Dancing Stars on Me——几何

2017-09-16 20:22 351 查看
题意:判断n个星星是否能组成正多边形

思路:因为坐标都是整数,所以星星如果能组成正多边形,那么这个多边形一定是正方形,所以对于n不等于4的排除就好,对于n等于4的,判断所有不重复的边中是否有4条边相等就好

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
const int maxn = 110;
int T, N;
struct Node {
int x, y;
}node[maxn];
struct Edge {
int len;
}edge[maxn * maxn];
map<int, int> Map;

int main() {
scanf("%d", &T);
for (int kase = 1; kase <= T; kase++) {
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
scanf("%d %d", &node[i].x, &node[i].y);
}
if (N != 4) { printf("NO\n"); continue; }
int cnt = 0;
for (int i = 1; i <= 4; i++) {
for (int j = i + 1; j <= 4; j++) {
edge[++cnt].len = (node[i].x - node[j].x) * (node[i].x - node[j].x) + (node[i].y - node[j].y) * (node[i].y - node[j].y);
}
}
Map.clear();
bool ok = false;
for (int i = 1; i <= cnt; i++) {
Map[edge[i].len]++;
if (Map[edge[i].len] == 4) { ok = true; break; }
}
if (ok) printf("YES\n");
else printf("NO\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: