K - 正方形_Java

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();
	}
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值