CodeforcesRound #113 (Div.2) B. judge whether the polygon is in the convex hull.

Source: Internet
Author: User
Click the question to open the link Convex Polygon A and polygon B to determine whether B is strictly within. Note that AB is important. Combine the vertices on A and B to obtain the convex hull. If the vertices on the convex hull are A point of B, then B is definitely not in. Or A certain point on B is on the side of the convex hull, which means that B is not strictly in. There is a clever way to deal with this problem. You only need to find the convex hull,

Click the question to open the link Convex Polygon A and polygon B to determine whether B is strictly within. Note that AB is important. Combine the vertices on A and B to obtain the convex hull. If the vertices on the convex hull are A point of B, then B is definitely not in. Or A certain point on B is on the side of the convex hull, which means that B is not strictly in. There is a clever way to deal with this problem. You only need to find the convex hull,

Click to open the link

Convex Polygon A and polygon B determine whether B is strictly within.

Note that AB is important.

Combine the vertices on A and B to obtain the convex hull. If the vertices on the convex hull are A point of B, then B is definitely not in.

Or A point on B is on the side of the convex hull, which means that B is not strictly in.

This processing has a clever way. You only need to change the value of <= to <that is to say, all vertices on the side of a convex packet are recorded in the convex packet.

You cannot focus on it.


int   cmp(double x){      if(fabs(x) < 1e-8)  return 0 ;      return  x > 0 ? 1 : -1 ;}struct  point{        double x , y ;        int k ;        point(){}        point(double _x , double _y):x(_x) , y(_y){}        point operator - (const point &o){              return  point(x - o.x , y - o.y) ;        }        friend double operator ^ (const point &a , const point &b){              return a.x * b.y - a.y * b.x ;        }        friend bool operator < (const point &a , const point &b){              if(cmp(a.x - b.x) != 0)  return cmp(a.x - b.x) < 0 ;              if(cmp(a.y - b.y) != 0)  return  cmp(a.y - b.y) < 0 ;              return  a.k < b.k ;        }        friend bool operator == (const point &a , const point &b){             return cmp(a.x - b.x) == 0 && cmp(a.y - b.y) == 0 ;        }};vector
 
    convex_hull(vector
  
    a){       vector
   
      s(a.size() * 2 + 5) ;       sort(a.begin() , a.end()) ;       int m = 0  ;       for(int i = 0 ; i < a.size() ; i++){            while(m > 1 && cmp((s[m-1] - s[m-2]) ^ (a[i] - s[m-2])) < 0) m-- ;            s[m++] = a[i] ;       }       int k = m ;       for(int i = a.size() - 2 ; i >= 0 ; i--){            while(m > k && cmp((s[m-1] - s[m-2]) ^ (a[i] - s[m-2])) < 0) m-- ;            s[m++] = a[i] ;       }       s.resize(m) ;       if(a.size() > 1) s.resize(m-1) ;       return s ;}int   main(){      int i , n ,  m  , ans = 0  ;      vector
    
      lis(200000) ;      cin>>n;      for(i = 0 ; i < n ; i++){          scanf("%lf%lf" , &lis[i].x , &lis[i].y) ;          lis[i].k = 0 ;      }      cin>>m ;      for(i = 0 ; i < m ; i++){          scanf("%lf%lf" , &lis[n+i].x , &lis[n+i].y) ;          lis[n+i].k = 1 ;      }      lis.resize(n + m)  ;      vector
     
       hull = convex_hull(lis)  ;      for(i = 0 ; i < hull.size() ; i++){          if(hull[i].k){               ans = 1 ;               break  ;          }      }      printf("%s\n" , ans ? "NO" : "YES") ;      return  0 ;}
     
    
   
  
 

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.