【java练习】SDUT 2444 正方形

Problem 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

Sample Output

YES
NO
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		 int t=s.nextInt();
		 while(t-->0)
		 {
			pan x1= new pan(s.nextInt(),s.nextInt());
			pan x2= new pan(s.nextInt(),s.nextInt());
			pan x3=new pan(s.nextInt(),s.nextInt());
			pan x4=new pan(s.nextInt(),s.nextInt());
			if(x1.f(x2)==x2.f(x3)&&x1.f(x2)==x3.f(x4)&&x1.f(x2)==x4.f(x1)&&x1.f(x3)==x2.f(x4))
				System.out.println("YES");//对角线相等
			else 
				System.out.println("NO");
		 }
		 s.close();
	}
}

class pan {
	int x,y;

	public pan(int x, int y) {
		super();
		this.x = x;
		this.y = y;
	}

	public int f(pan p) {
		return (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y);
	}
}

猜你喜欢

转载自blog.csdn.net/flyf000/article/details/83449758