The Great Divide of The ultraviolet A 10256 to determine whether two convex packets are separated.

Source: Internet
Author: User

The Great Divide of The ultraviolet A 10256 to determine whether two convex packets are separated.


Calculate Two convex packets from the given two vertex sets,

Then determine whether the two convex packets are separated.


# Include <cstdio> # include <vector> # include <cmath> # include <algorithm> using namespace std; const double eps = 1e-10; double dcmp (double x) {if (fabs (x) <eps) return 0; else return x <0? -1: 1 ;}struct Point {double x, y; Point (double x = 0, double y = 0): x (x), y (y ){}}; typedef Point Vector; Vector operator-(const Point & A, const Point & B) {return Vector (. x-B.x,. y-B.y);} double Cross (const Vector & A, const Vector & B) {return. x * B. y-. y * B. x;} double Dot (const Vector & A, const Vector & B) {return. x * B. x +. y * B. y;} bool operator <(const Point & p1, const Point & p2) {return p1.x <P2.x | (p1.x = p2.x & p1.y <p2.y);} bool operator = (const Point & p1, const Point & p2) {return p1.x = p2.x & p1.y = p2.y;} bool SegmentProperIntersection (const Point & a1, const Point & a2, const Point & b1, const Point & b2) {double c1 = Cross (a2-a1, b1-a1), c2 = Cross (a2-a1, b2-a1), c3 = Cross (b2-b1, a1-b1), c4 = Cross (b2-b1, a2-b1 ); return dcmp (c1) * dcmp (c2) <0 & dcmp (c3) * dcmp (c4) <0;} bool OnSegm Ent (const Point & p, const Point & a1, const Point & a2) {return dcmp (Cross (a1-p, a2-p) = 0 & dcmp (Dot (a1-p, a2-p) <0;} // Point Set convex hull // if you do not want an Input Point on the side of the convex hull, change the two <= to <// if you do not mind that the point set is modified, you can pass the reference vector <Point> ConvexHull (vector <Point> p) {// preprocessing to delete the repeated vertex sort (p. begin (), p. end (); p. erase (unique (p. begin (), p. end (), p. end (); int n = p. size (); int m = 0; vector <Point> ch (n + 1); for (int I = 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];} int k = m; for (int I = n-2; I> = 0; I --) {while (m> k & Cross (ch [s-1]-ch [m-2], p [I]-ch [m-2]) <= 0) m --; ch [m ++] = p [I];} if (n> 1) m --; ch. resize (m); return ch;} int IsPointInPolygon (const Point & p, const vector <Point> & poly) {int wn = 0; int n = poly. size (); for (int I = 0; I <n; ++ I) {const Point & p1 = poly [I]; const Point & P2 = poly [(I + 1) % n]; if (p1 = p | p2 = p | OnSegment (p, p1, p2) return-1; // at the boundary int k = dcmp (Cross (P2-P1, p-p1); int d1 = dcmp (p1.y-p. y); int d2 = dcmp (p2.y-p. y); if (k> 0 & d1 <= 0 & d2> 0) wn ++; if (k <0 & d2 <= 0 & d1> 0) wn --;} if (wn! = 0) return 1; return 0;} bool ConvexPolygonDisjoint (const vector <Point> counts, const vector <Point> ch2) {int c1 = ch1.size (); int c2 = ch2.size (); for (int I = 0; I <c1; ++ I) if (IsPointInPolygon (random [I], ch2 )! = 0) return false; for (int I = 0; I <c2; ++ I) if (IsPointInPolygon (ch2 [I], callback )! = 0) return false; for (int I = 0; I <c1; ++ I) for (int j = 0; j <c2; ++ j) if (SegmentProperIntersection (products [I], products [(I + 1) % c1], ch2 [j], ch2 [(j + 1) % c2]) return false; return true;} int main () {int n, m; while (scanf ("% d", & n, & m) = 2 & n> 0 & m> 0) {vector <Point> P1, P2; double x, y; for (int I = 0; I <n; I ++) {scanf ("% lf", & x, & y); P1.push _ back (Point (x, y ));} for (int I = 0; I <m; I ++) {scanf ("% lf", & x, & y); P2.push _ back (Point (x, y);} if (ConvexPolygonDisjoint (ConvexHull (P1), ConvexHull (P2) printf ("Yes \ n"); else printf ("No \ n ");} 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.