HDU5533Dancing Stars on Me(长春题)

题目链接
题目大意:给定几个点(整数点),判断是否能形成正多边形
思路:因为是整数点,所以只能为正方形,所以首先要判断输入的点数4,对于四边形,任意两点的距离和另外两点距离相等,即为正方形。

Input
The first line contains a integer T indicating the total number of test cases. Each test case begins with an integer n, denoting the number of stars in the sky. Following n lines, each contains 2 integers xi,yi, describe the coordinates of n stars.

1≤T≤300
3≤n≤100
−10000≤xi,yi≤10000
All coordinates are distinct.

Output
For each test case, please output “YES” if the stars can form a regular polygon. Otherwise, output “NO” (both without quotes).

Sample Input
3
3
0 0
1 1
1 0
4
0 0
0 1
1 0
1 1
5
0 0
0 1
0 2
2 2
2 0

Sample Output
NO
YES
NO

#include <iostream>
#include <cstdio>
#include <cmath>
#include<math.h>
using namespace std;
typedef struct{
    int x,y;
} point;

int main()
{
    int t;
    int n,i;
    double dis(point p1,point p2);
    scanf("%d",&t);
    while (t--) {
        scanf("%d",&n);
        point p[100];
        for(i=0;i<n;i++)
              scanf("%d%d",&p[i].x,&p[i].y);
//        for(i=0;i<n;i++)
//            printf("p[%d]:%d\t%d",i,p[i].x,p[i].y);
        if(n!=4)
            printf("NO\n");
        else if(dis(p[0],p[1])==dis(p[2],p[3])&&dis(p[0],p[2])==dis(p[1],p[3])
                &&dis(p[0],p[3])==dis(p[1],p[2]))/*判断是否为正方形*/
            printf("YES\n");

        else
            printf("NO\n");
    }


    return 0;
}
/*距离公式*/
double dis(point p1,point p2)
{
    int dis;
    dis=pow((p1.x-p2.x),2)+pow((p1.y-p2.y),2);
    return dis;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值