Hihocoder 1040 (Rectangle judging)

Source: Internet
Author: User

Topic Link: Portal

The main topic: give you four line segments, to determine whether to surround an area greater than 0 rectangle, can output Yes, cannot output no

Topic Ideas:

A valid four line segment should meet

1. There should be four different points

2. The slope of the line segment is divided into two groups, the same group within the group is different

3. If a line with a slope of 0 or a non-existent slope is to be ==-1, the product of the line with different slope will be seen. "YES": "NO"

#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<cstring>#include<stack>#include<cctype>#include<queue>#include<string>#include<vector>#include<Set>#include<map>#include<climits>#defineLson Root<<1,l,mid#defineRson Root<<1|1,mid+1,r#defineFi first#defineSe Second#definePing (x, y) ((x-y) * (x-y))#defineMST (x, y) memset (x,y,sizeof (x))#defineMCP (x, y) memcpy (x,y,sizeof (y))using namespacestd;#defineGamma 0.5772156649015328606065120#defineMOD 1000000007#defineINF 0x3f3f3f3f#defineN 200005#defineMAXN 1050typedef pair<int,int>Pii;typedefLong LongLL;intn,m;structnode{intx, y; BOOL operator< (ConstNode&a)Const{        if(x==a.x)returny<a.y; returnx<a.x; }}node[4][2];map&LT;PII,int>M;///determine the number of verticesDoublek[5];///SlopeintMain () {inti,j,group,x,y,v;  while(SCANF ("%d", &group)! =EOF) {         while(group--) {m.clear ();  for(i=0; i<=3;++i) {scanf ("%d%d", &node[i][0].x,&node[i][0].y); scanf ("%d%d", &node[i][1].x,&node[i][1].y); Sort (Node[i],node[i]+2); }            intnum=0;  for(i=0; i<=3; ++i) for(j=0; j<=1;++j) {PII P=Make_pair (NODE[I][J].X,NODE[I][J].Y); if(! M[P]) + +num; M[P]=1; }            if(num!=4) {printf ("no\n");Continue;}///the number of vertices is not 4,no             for(i=0;i<4;++i) {                if(node[i][0].x==node[i][1].x) {///slope does not existk[i]=inf; Continue; }                Else if(node[i][0].y==node[i][1].y) {K[i]=0; Continue; }                Else{K[i]=(Double) (node[i][1].y-node[i][0].Y)/(Double) (node[i][1].x-node[i][0].x); }} sort (K,k+4); if(Fabs (k[0]-k[1]) <1e-5&&fabs (k[2]-k[3]) <1e-5){                if(Fabs (k[1]-k[2]) <1e-5) printf ("no\n"); Else{                    if(Fabs (k[1]*k[2]+1) <1e-5) printf ("yes\n"); Else if(Fabs (k[0]) <1e-5&&fabs (k[3]-inf) <1e-5) printf ("yes\n"); Elseprintf"no\n"); }            }            Elseprintf"no\n"); }    }    return 0;}

Hihocoder 1040 (Rectangle judging)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.