当前位置: 代码迷 >> 综合 >> Lan Xiang's Square
  详细解决方案

Lan Xiang's Square

热度:75   发布时间:2023-12-15 15:50:23.0

Lan Xiang's Square

时间限制: 1000 ms  |  内存限制: 65535 KB
难度: 0
描述

       Excavator technology which is strong, fast to Shandong to find Lan Xiang.

       Then the question comes.. :)

       for this problem , i will give you four points. you just judge if they can form a square.

       if they can, print "Yes", else print "No".

       Easy ?  just AC it.

输入
T <= 105 cases.
for every case
four points, and every point is a grid point .-10^8 <= all interger <= 10^8。
grid point is both x and y are interger.
输出

Yes or No


代码实现:

//求四个点是否能够构成一个正方形 
#include<stdlib.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
struct AC
{
double x,y;
} p[100];
double len[100];
//求A,B两点的距离 
double AC_it(AC a,AC b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
for(int i=0; i<4; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
int m=0;
for(int i=0; i<4; i++)
{
for(int j=i+1; j<4; j++)
{
len[m++]=AC_it(p[i],p[j]);
}
}
sort(len,len+6);
if(len[0]==len[1]&&len[1]==len[2]&&len[2]==len[3]);
else
{
puts("No");
continue;
}
if(len[4]==len[5]);
else
{
puts("No");
continue;
}
if(len[0]!=len[4])
;
else
{
puts("No");
continue;
}
puts("Yes");
}
}


样例输入
1
1 1
-1 1
-1 -1
1 -1
样例输出
Yes