随机给定四个点(二维空间),判断这四个点能否构成正方形。
输入描述:
第一行为一个整数,表示需要判断的数据组数;
余下每行都有8个浮点数表示四个点的坐标。
输出描述:
输出为一行,如果能构成正方形,输出Yes,否则输出No。
输入样例:
3
0 0 0 1 1 0 1 1
1 1 2 0 3 1 2 2
0 0 -1 1 -2 1 -2 0
输出样例:
Yes
Yes
No
思路:
计算所有点之间的distance。
如果能构成正方形,结果必定只有两个。
如果两个结果的比值为cos(PI/4),返回Yes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SquareProblem
{
// Class Point
class Point
{
public int x;
public int y;
}
class Program
{
// Calculate the distance between tow point.
static double Distance(Point a, Point b)
{
double dis = Math.Sqrt((a