# CF14C four segments (computational geometry)

Source: Internet
Author: User

Test instructions

Give four segments (coordinates of two endpoints).

Determine if the four segments can form a rectangle. (The four edges of the rectangle are parallel to the x-axis or y-axis)

Ideas:

Calculate geometry

Code:

`classpoint{ Public:    intx, y; voidReadd (intXxintyy) {x=xx; Y=yy; }};classsegment{ Public: Point startt,endd; intlength; intType;//1: Transverse 2: vertical-1: Oblique    voidReadd (intX1,intY1,intX2,inty2)        {Startt.readd (x1,y1);        Endd.readd (X2,Y2); Length=(int) sqrt (Double) (x2-x1) * (X2-X1) + (Double) (y2-y1) * (y2-y1)); }    intTypecheck () {Type=-1; if(startt.x==endd.x) {Type=2; }        if(startt.y==endd.y) {Type=1; }    }}; Segment s[5];BOOLSamepoint (Point A,point b) {if(a.x==b.x&&a.y==b.y) {        return true; }    return false;}BOOLsolve () {if(s[1].startt.y<s[2].startt.y) {swap (s[1],s[2]); }    if(s[1].startt.x>s[1].endd.x) {swap (s[1].startt,s[1].endd); }    if(s[2].startt.x>s[2].endd.x) {swap (s[2].startt,s[2].endd); }    if(s[3].startt.x>s[4].startt.x) {swap (s[3],s[4]); }    if(s[3].startt.y<s[3].endd.y) {swap (s[3].startt,s[3].endd); }    if(s[4].startt.y<s[4].endd.y) {swap (s[4].startt,s[4].endd); }    if(Samepoint (s[1].startt,s[3].STARTT) &&Samepoint (s[1].endd,s[4].STARTT) &&Samepoint (s[3].endd,s[2].STARTT) &&Samepoint (s[2].endd,s[4].endd)) {return true; }    return false;}BOOLCmp1 (Segment a,segment b) {returna.type<B.type;}intMain () {Rep (I,1,4){        intX1,y1,x2,y2; CIN>>x1>>y1>>x2>>Y2;        S[i].readd (X1,Y1,X2,Y2);    S[i].typecheck (); } Rep (I,1,4){        if(s[i].length==0|| S[i]. type==-1) {puts ("NO"); return 0; }} sort (S+1, s+5, CMP1); if(! (s[1].length==s[2].length&&s[3].length==s[4].length)) {puts ("NO"); return 0; }    if(Solve ()) {puts ("YES"); }    Else{puts ("NO"); }    return 0;}`

CF14C four segments (computational geometry)

Related Keywords:

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.