CF-14C - Four Segments(几何)

来源:互联网 发布:防范电信网络诈骗图片 编辑:程序博客网 时间:2024/05/17 10:04
C - Four Segments

Crawling in process...Crawling failedTime Limit:2000MS    Memory Limit:65536KB   64bit IO Format:%I64d & %I64u

SubmitStatusPracticeCodeForces 14C

Description

Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him.

Input

The input data contain four lines. Each of these lines contains four integers x1,y1,x2,y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points.

Output

Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO».

Sample Input

Input
1 1 6 11 0 6 06 0 6 11 1 1 0
Output
YES
Input
0 0 0 32 0 0 02 2 2 00 2 2 2
Output
NO

 

思路:简单几何,先判断是个四边形,判断有条边与X轴平行,再判断每个角是90度,就是矩形了。

       判断有点小技巧,具体看代码。

失误点:比赛的时候粗心,看落了个条件,要求要有边和x轴平行。结果╮(╯▽╰)╭

 

#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<map>using namespace std;const double pi=3.1415926;class node{public:  int x,y,xx,yy;  int z;}s[77];int num[44];map<int,int>mp;int main(){  int a,b,c,d;  while(cin>>a>>b>>c>>d)  {   memset(num,0,sizeof(num));     bool ans=0;     for(int i=0;i<4;i++)     {  if(a==c&&b==d)ans=1;       s[i].x=a;s[i].y=b;s[i].xx=c;s[i].yy=d;///交换点生成一遍好判断       s[i+4].x=c;s[i+4].y=d;s[i+4].xx=a;s[i+4].yy=b;       if(i!=3)cin>>a>>b>>c>>d;     }     bool flag=1;     for(int i=0;i<4;i++)     for(int j=0;j<8;j++)     { if(i==j)continue;       if(s[i].x==s[j].x&&s[i].y==s[j].y)        num[i]++;///判断是个四边形,那有且仅有两个点一样        if(s[i].y==s[i].yy)flag=0;///判断有条边是x轴平行就行了     }     if(flag)ans=1;     for(int i=0;i<4;i++)      if(num[i]!=1)ans=1;     for(int i=0;i<4;i++)     for(int j=0;j<8;j++)     { if(i==j)continue;        double x,y,xx,yy,z,zz;       if(s[i].x==s[j].x&&s[i].y==s[j].y)///判断角都是90度        {///向量知识,(x,y)*(xx,yy)=(长度乘积)cos degree;          x=s[i].x-s[i].xx;          y=s[i].y-s[i].yy;          xx=s[i].x-s[j].xx;          yy=s[i].y-s[j].yy;          z=x*xx+y*yy;          zz=sqrt(x*x+y*y)*sqrt(xx*xx+yy*yy);          z=z/zz;          z=acos(z)/pi*180;         /// cout<<z<<endl;          if(abs(z-90.0)>0.0001)ans=1;        }     }     if(ans)cout<<"NO\n";     else cout<<"YES\n";  }}


 

 

 

 

 

 

 

原创粉丝点击