简单的几何学
时间限制: 1 内存限制: 128 MB
题目描述
这是一个十分简单的几何学题目。现在给出N个点的坐标(x,y),保证x和y都是整数,你的任务是判断这N个点是否能构成正N边形。
输入
单组输入数据
第一行是N,(2<N<1000)
接下来有N行,每行两个数,代表这个点的坐标(x,y)
−1000≤x,y≤1000 且保证都为整数
输出
输出一行结果
如果可以构成正N边形,输出Yes,否则输出No
样例输入
4
0 50
0 -50
50 0
-50 0
样例输出
Yes
只有正四边形能由整数点构成,然后暴力求出所有边的长度判断是否四边相等,斜边最大且相等
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <climits>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
using namespace std;
typedef long long ll;
static const int MAX_N = 1e6 + 5;
static const int N = 1005;
static const ll Mod = 2009;
static const int inf = (1 << 30) - 1;
int ans[10];
struct Point{
int x, y;
Point(){}
Point(int _x, int _y){x = _x, y = _y;}
}p[N];
int get_dis(Point a, Point b){
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
void solve(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
scanf("%d", &n);
for(int i = 0; i < n; ++i) scanf("%d%d", &p[i].x, &p[i].y);
if(n != 4) puts("No");
else{
int cnt = 0;
for(int i = 0; i < 3; ++i){
for(int j = i + 1; j < 4; ++j)
ans[cnt++] = get_dis(Point(p[i].x, p[i].y), Point(p[j].x, p[j].y));
}
sort(ans, ans + cnt);
if(ans[0] == ans[1] && ans[1] == ans[2] && ans[2] == ans[3] &&
ans[4] == ans[5] && ans[4] != ans[0])
puts("Yes");
else puts("No");
}
}
int main(){
solve();
return 0;
}