HNUCM 1387 简单的几何学

                                       简单的几何学

时间限制: 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;
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值