UVA 10256 the Great Divide (convex hull, polygon position Relationship)

Source: Internet
Author: User

Title Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34148

Ideas

Convex bag

Find out the red and blue dot convex hull, the remaining problem is to determine whether two convex bag is absent.

You need to determine two points:

1) intersection of segments on convex package

2) The points on the convex hull are included in the other convex package.

Code

1#include <cmath>2#include <vector>3#include <cstdio>4#include <algorithm>5 using namespacestd;6 7 Const DoubleEPS = 1e-Ten;8 intDCMP (Doublex) {9     if(Fabs (x) <eps)return 0;Else returnx<0? -1:1;Ten } One  A structPt { -     Doublex, y; -Pt (Doublex=0,Doubley=0): X (x), Y (y) {}; the }; - typedef Pt VEC; -Vecoperator-(Pt a,pt B) {returnVEC (a.x-b.x,a.y-b.y); } - BOOL operator==(Pt a,pt B) { +     returnDCMP (a.x-b.x) = =0&& dcmp (a.y-b.y) = =0; - } + BOOL operator< (Constpt& A,Constpt&b) { A     returna.x<b.x | | (a.x==b.x && a.y<b.y); at } - DoubleDot (VEC A,vec B) {returna.x*b.x+a.y*b.y;} - DoubleCross (Pt a,pt B) {returna.x*b.y-a.y*b.x;} -  - BOOLsegintersection (Pt a1,pt a2,pt b1,pt b2) { -     DoubleC1 = Cross (A2-A1,B1-A1), C2 = Cross (a2-a1,b2-A1), inC3 = Cross (B2-B1,A1-B1), C4=cross (b2-b1,a2-B1); -   returnDCMP (C1) *dcmp (C2) <0&& dcmp (C3) *dcmp (C4) <0; to } + BOOLonseg (Pt p,pt a1,pt A2) { -     returnDCMP (Cross (p-a1,p-a2)) = =0&& dcmp (Dot (P-A1,P-A2)) <0; the } *  $ Panax Notoginseng intN; -Vector<pt> Convexhull (vector<pt>p) { the sort (P.begin (), P.end ()); + p.erase (Unique (P.begin (), P.end ()), P.end ()); A     intn=p.size (); the     intm=0; +Vector<pt> CH (n+1); -      for(intI=0; i<n;i++) { $          while(m>1&& Cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--; $ch[m++]=P[i]; -     } -     intk=m; the      for(inti=n-2; i>=0; i--) { -          while(M>k && Cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--;Wuyich[m++]=P[i]; the     } -     if(n>1) m--; Wu ch.resize (m); -     returnch; About } $  - intIspointinpolygon (Pt p,vector<pt>&Poly) { -     intwn=0; -     intn=poly.size (); A      for(intI=0; i<n;i++) { +pt& p1=Poly[i]; thept& p2=poly[(i+1)%n]; -         if(p1==p | | p2==p | | Onseg (P,P1,P2))return-1; $         intK=DCMP (Cross (p2-p1,p-p1)); the         intD1=DCMP (p1.y-p.y); the         intD2=DCMP (p2.y-p.y); the         if(k>0&& d1<=0&& d2>0) wn++; the         if(k<0&& d2<=0&& d1>0) wn--; -     } in     if(wn!=0)return 1; the     return 0; the } About BOOLConvexpolygondisjoint (vector<pt> ch1,vector<pt>CH2) { the     intC1=ch1.size (), c2=ch2.size (); the      for(intI=0; i<c1;i++) the         if(Ispointinpolygon (CH1[I],CH2)! =0)return false; +      for(intI=0; i<c2;i++) -         if(Ispointinpolygon (ch2[i],ch1)! =0)return false; the      for(intI=0; i<c1;i++)Bayi          for(intj=0; j<c2;j++) the             if(Segintersection (ch1[i],ch1[(i+1)%c1],ch2[j],ch2[(j+1)%C2]))return false; the     return true; - } -  the intMain () { the     intn,m; the      while(SCANF ("%d%d", &n,&m) = =2&& N &&m) { theVector<pt>p1,p2; -         Doublex, y; the          for(intI=0; i<n;i++) { thescanf"%LF%LF",&x,&y); the P1.push_back (Pt (x, y));94         } the          for(intI=0; i<m;i++) { thescanf"%LF%LF",&x,&y); the P2.push_back (Pt (x, y));98         } About         if(Convexpolygondisjoint (Convexhull (P1), Convexhull (P2))) -Puts"Yes");ElsePuts"No");101     }102     return 0;103}

UVA 10256 the Great Divide (convex hull, polygon position Relationship)

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.