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");
}
}
思路:因为坐标都是整数,所以星星如果能组成正多边形,那么这个多边形一定是正方形,所以对于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");
}
}
相关文章推荐
- HDU 5533 Dancing Stars on Me (2015ACM/ICPC亚洲区长春 &&计算几何)
- [hdu 5533][2015ACM/ICPC亚洲区长春站] Dancing Stars on Me 计算几何
- hdu 5533 Dancing Stars on Me【计算几何】
- hdu 5533 Dancing Stars on Me(长春现场赛——几何题)
- HDU-5533 Dancing Stars on Me(几何/极点排序)
- HDU 5533 Dancing Stars on Me 计算几何瞎暴力
- Dancing Stars on Me HDU - 5533
- HDU-5533 Dancing stars on me
- HDU 5533:Dancing Stars on Me【数学】
- hdu 5533 Dancing Stars on Me(水)
- HDU 5533 Dancing Stars on Me(数学+水题)
- 【HDOJ5533】Dancing Stars on Me(计算几何)
- 文章标题 HDU 5533 : Dancing Stars on Me
- HDU 5533 Dancing Stars on Me
- hdu 5533 Dancing Stars on Me 【2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大)】
- HDU 5533 Dancing Stars on Me (凸包)
- HDU 5533 Dancing Stars on Me [数学]
- hdu 5533 Dancing Stars on Me
- HDU 5533 Dancing Stars on Me(凸包)
- 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me