Lan Xiang's Square
时间限制:1000 ms | 内存限制:65535 KB
难度:0
- 描述
-
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
- 提示
- you think this is a easy problem ? you dare submit, i promise you get a WA.
- 来源
- myself
-
上传者
思路:被水题坑得好惨Orz 两领边相等
两对角线相等(ps:边可能为0,我就是死在这里 ) 点是乱序的 得先排序(好像最先没有0这组数据
比赛时候我过了 后来重判把我给打回蓝翔了)#include<stdio.h> #include<string.h> #include<algorithm> #include<cmath> #include<iostream> using namespace std; struct ac { int x,y; } p[8]; bool cmp(ac xx,ac yy) { if(xx.x!=yy.x) return xx.x<yy.x; return xx.y>yy.y; } int len(int a,int b,int c,int d) { return sqrt((a-c)*(a-c)+(b-d)*(b-d)); } int main() { int t; cin>>t; while(t--) { for(int i=0; i<4; i++) cin>>p[i].x>>p[i].y; int s1,s2,s3,s4,s5,s6; sort(p,p+4,cmp); s1=len(p[0].x,p[0].y,p[3].x,p[3].y); s2=len(p[1].x,p[1].y,p[2].x,p[2].y); /*两邻边*/ if(s1!=s2||s1==0) { cout<<"No"<<endl; continue; } else if(s1==s2) { if(((p[0].x-p[3].x)*(p[1].x-p[2].x)+(p[1].y-p[2].y)*(p[0].y-p[3].y))==0)//对角线相等 cout<<"Yes"<<endl; else cout<<"No"<<endl; } } }