题目链接
题目大意:给定几个点(整数点),判断是否能形成正多边形
思路:因为是整数点,所以只能为正方形,所以首先要判断输入的点数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;
}