Description
给出四个点,判断这四个点能否构成一个正方形。
Input
输入的第一行包含一个整数T(T≤30)表示数据组数,每组数据只有一行,包括8个整数x1, y1, x2, y2,x3,y3,x4,y4(数据均在-1000,1000 之间)以逆时针顺序给出四个点的坐标。
Output
每组数据输出一行,如果是正方形,则输出: YES, 否则,输出:NO。
Sample
Input
2
0 0 1 0 1 1 0 1
-1 0 0 -2 1 0 2 0
Output
YES
NO
import java.util.Scanner;
class Point {
int x,y;
public Point (int x,int y) {
super();
this.x=x;
this.y=y;
}
public boolean jugde(Point a,Point b,Point c,Point d) {
int n,m;
m=(int) (Math.pow((a.x-c.x),2)+Math.pow((a.y-c.y),2));
n=(int) (Math.pow((b.x-d.x),2)+Math.pow((b.y-d.y),2));
if(n==m && ((a.x-c.x)*(b.x-d.x)+((a.y-c.y)*(b.y-d.y))==0))
return true;
else
return false;
}
}
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int T = input.nextInt();
while(T--!=0) {
int x[] = new int[4];
int y[] = new int[4];
for(int i=0;i<4;i++) {
x[i]=input.nextInt();
y[i]=input.nextInt();
}
Point a = new Point(x[0],y[0]);
Point b = new Point(x[1],y[1]);
Point c = new Point(x[2],y[2]);
Point d = new Point(x[3],y[3]);
Point judge = new Point();
if(judge.jugde(a, b, c, d))
System.out.println("YES");
else
System.out.println("NO");
}
input.close();
}
}
333

被折叠的 条评论
为什么被折叠?



