Lan Xiang's Square

编程入门 行业动态 更新时间:2024-10-24 22:18:44

<a href=https://www.elefans.com/category/jswz/34/1764800.html style=Lan Xiang's Square"/>

Lan Xiang's Square

描述

       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");elseprintf("No\n");}return 0;
}


更多推荐

Lan Xiang's Square

本文发布于:2024-02-11 05:55:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1679499.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Lan   Xiang   Square

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!