描述
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 样例输入
-
1 1 1 -1 1 -1 -1 1 -1
样例输出
-
Yes
-
TMD lz什么也不想说 多大点事 就不能好好说话吗 干嘛要表现出大数的样子 kao 气死我了
-
题解:对角线相等 不一定是矩形 等腰梯形也行 所以要加上 对角线重合 这样就是矩形了 如果 相邻边也相等 则为正方形
-
#include<stdio.h> struct POINT{ int x,y; }p[4]; int dis(POINT a, POINT b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } bool mid(POINT a, POINT b, POINT c, POINT d) { if(a.x + b.x == c.x + d.x && a.y + b.y == c.y + d.y) return true; return false; } bool isSquare() { for(int i = 0; i < 4; i ++){ for(int j = i + 1; j < 4; j ++) if(p[i].x == p[j].x && p[i].y == p[j].y) return false; } if(dis(p[0], p[1]) == dis(p[2], p[3]) && mid(p[0], p[1], p[2], p[3]) && dis(p[0], p[2]) == dis(p[0], p[3])) return true; if(dis(p[0], p[2]) == dis(p[1], p[3]) && mid(p[0], p[2], p[1], p[3]) && dis(p[0], p[1]) == dis(p[0], p[3])) return true; if(dis(p[0], p[3]) == dis(p[1], p[2]) && mid(p[0], p[3], p[1], p[2]) && dis(p[0], p[1]) == dis(p[0], p[2])) return true; return false; } int main() { int n; scanf("%d",&n); while(n--) { scanf("%d%d%d%d%d%d%d%d",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y,&p[3].x,&p[3].y); if(isSquare()) printf("Yes\n"); else printf("No\n"); } return 0; }