1 #include<stdio.h>
  2 #include<string.h>
  3 #include<stdlib.h>
  4 #include<math.h>
  5 #include <string>
  6 #include <iostream>
  7 #include<algorithm>
  8 
  9 using namespace std;
 10 
 11 const int maxn = 555;
 12 const int maxisn = 10;
 13 const double eps = 1e-8;
 14 const double pi = acos(-1.0);
 15 int dcmp(double x)
 16 {
 17     if(x > eps) return 1;
 18     return x < -eps ? -1 : 0;
 19 }
 20 inline double min(double a, double b)
 21 {return a < b ? a : b;}
 22 inline double max(double a, double b)
 23 {return a > b ? a : b;}
 24 inline double Sqr(double x)
 25 {return x * x;}
 26 struct Point
 27 {
 28     double x, y;
 29     Point(){x = y = 0;}
 30     Point(double a, double b)
 31     {x = a, y = b;}
 32     inline Point operator-(const Point &b)const
 33     {return Point(x - b.x, y - b.y);}
 34     inline Point operator+(const Point &b)const
 35     {return Point(x + b.x, y + b.y);}
 36     inline double dot(const Point &b)const
 37     {return x * b.x + y * b.y;}
 38     inline double cross(const Point &b, const Point &c)const
 39     {return (b.x - x) * (c.y - y) - (c.x - x) * (b.y - y);}
 40 };
 41 Point LineCross(const Point &a, const Point &b, const Point &c, const Point &d)
 42 {
 43     double u = a.cross(b, c), v = b.cross(a, d);
 44     return Point((c.x * v + d.x * u) / (u + v), (c.y * v + d.y * u) / (u + v));
 45 }
 46 double PolygonArea(Point p[], int n)
 47 {
 48     if(n < 3) return 0.0;
 49     double s = p[0].y * (p[n - 1].x - p[1].x);
 50     p[n] = p[0];
 51     for(int i = 1; i < n; ++ i)
 52         s += p[i].y * (p[i - 1].x - p[i + 1].x);
 53     return fabs(s * 0.5);
 54 }
 55 double CPIA(Point a[], Point b[], int na, int nb)//ConvexPolygonIntersectArea
 56 {
 57     Point p[maxisn], tmp[maxisn];
 58     int i, j, tn, sflag, eflag;
 59     a[na] = a[0], b[nb] = b[0];
 60     memcpy(p, b, sizeof(Point) * (nb + 1));
 61     for(i = 0; i < na && nb > 2; ++ i)
 62     {
 63         sflag = dcmp(a[i].cross(a[i + 1], p[0]));
 64         for(j = tn = 0; j < nb; ++ j, sflag = eflag)
 65         {
 66             if(sflag >= 0) tmp[tn ++] = p[j];
 67             eflag = dcmp(a[i].cross(a[i + 1], p[j + 1]));
 68             if((sflag ^ eflag) == -2)
 69                 tmp[tn ++] = LineCross(a[i], a[i + 1], p[j], p[j + 1]);
 70         }
 71         memcpy(p, tmp, sizeof(Point) * tn);
 72         nb = tn, p[nb] = p[0];
 73     }
 74     if(nb < 3) return 0.0;
 75     return PolygonArea(p, nb);
 76 }
 77 double SPIA(Point a[], Point b[], int na, int nb)//SimplePolygonIntersectArea
 78 {
 79     int i, j;
 80     Point t1[4], t2[4];
 81     double res = 0, if_clock_t1, if_clock_t2;
 82     a[na] = t1[0] = a[0], b[nb] = t2[0] = b[0];
 83     for(i = 2; i < na; ++ i)
 84     {
 85         t1[1] = a[i - 1], t1[2] = a[i];
 86         if_clock_t1 = dcmp(t1[0].cross(t1[1], t1[2]));
 87         if(if_clock_t1 < 0) std::swap(t1[1], t1[2]);
 88         for(j = 2; j < nb; ++ j)
 89         {
 90             t2[1] = b[j - 1], t2[2] = b[j];
 91             if_clock_t2 = dcmp(t2[0].cross(t2[1], t2[2]));
 92             if(if_clock_t2 < 0) std::swap(t2[1], t2[2]);
 93             res += CPIA(t1, t2, 3, 3) * if_clock_t1 * if_clock_t2;
 94         }
 95     }
 96     return res;
 97 }
 98 Point p1[maxn], p2[maxn];
 99 int n1, n2;
100 int main()
101 {
102     int i;
103     int cas = 1;
104     while(scanf("%d", &n1) != EOF)
105     {
106         for(i = 0; i < n1; ++ i) scanf("%lf%lf", &p1[i].x, &p1[i].y);
107         scanf("%d",&n2);
108         for(i = 0; i < n2; ++ i) scanf("%lf%lf", &p2[i].x, &p2[i].y);
109         
110         double res = SPIA(p1, p2, n1, n2);
111         if(fabs(res)>=0.0000001)
112             printf("Case %d: Yes\n",cas++);
113         else
114             printf("Case %d: No\n",cas++);
115         
116         //printf("%.2f\n", SPIA(p1, p2, n1, n2) + eps);
117     }
118     return 0;
119 }