标签:
题目大意:给四条线段,问能否构成一个矩形?
题目分析:先判断能否构成四边形,然后选一条边,看另外三条边中是否为一条与他平行,两条垂直。
代码如下:
# include<iostream> # include<cstdio> # include<cmath> # include<set> # include<cstring> # include<algorithm> using namespace std; # define LL long long const double inf=1e20; const double eps=1e-20; struct Edge { LL x,y; double k; }; Edge e[4]; set<LL>s; double getK(int i) { if(e[i].x==0) return inf; return (double)e[i].y/(double)e[i].x; } bool ok(int i,int j) { return e[i].x*e[j].x+e[i].y*e[j].y==0ll; } bool judge() { if(s.size()!=4) return false; int cnt1=0,cnt2=0; for(int i=1;i<4;++i){ if(ok(0,i)) ++cnt1; if(e[0].k==e[i].k) ++cnt2; } return cnt1==2&&cnt2==1; } int main() { int T; scanf("%d",&T); while(T--) { LL a,b,c,d; s.clear(); for(int i=0;i<4;++i){ scanf("%lld%lld%lld%lld",&a,&b,&c,&d); s.insert(a*100000ll+b); s.insert(c*100000ll+d); e[i].x=c-a; e[i].y=d-b; e[i].k=getK(i); } if(judge()) printf("YES\n"); else printf("NO\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/20143605--pcx/p/5475168.html