File size: 3,398 Bytes
c4b0eef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
  >>~~ UVa Online Judge ACM Problem Solution ~~<<

  ID: 10005
  Name: Packing polygons
  Problem: https://onlinejudge.org/external/100/10005.pdf
  Language: C++

  Author: Arash Shakery
  Email: [email protected]
*/

#include <bits/stdc++.h>
using namespace std;

#define EPS 1e-8

struct Point {
    double x, y;
    Point():x(0),y(0){}
    Point(double x, double y):x(x),y(y){}
    bool operator < (const Point &o) const { return x < o.x; }
    bool operator == (const Point &o) const { return fabs(x-o.x)<EPS && fabs(y-o.y)<EPS; }
    double operator * (const Point o) const { return x*o.x + y*o.y; }
    Point operator - (const Point o) const { return Point(x-o.x, y-o.y); }
    Point operator + (const Point o) const { return Point(x+o.x, y+o.y); }
    Point operator / (double den) const { return Point(x/den, y/den); }
};

std::istream& operator>> (std::istream& stream, Point& p) {
    stream >> p.x >> p.y;
    return stream;
}

double dist2(const Point p1, const Point p2) {
    double xx = p1.x - p2.x, yy = p1.y - p2.y;
    return xx*xx + yy*yy;
}

struct Line {
    double a, b, c;
    Line():a(0),b(0),c(1){}
    Line(double x, double y):a(x),b(y),c(1){}
    Line(double a, double b, double c):a(a),b(b),c(c){}
    Line(const Point p1, const Point p2) {
        if (fabs(p1.x - p2.x) < EPS) {
            b = 0;
            if (fabs(p1.x) < EPS) a=1, c=0;
            else a = -1/p1.x, c = 1;
        }
        else {
            a = p2.y - p1.y;
            b = p1.x - p2.x;
            c = -p1.y*b - p1.x*a;
        }
    }
    double y(double x0) { return (-a*x0 - c) / b; }
    double x(double y0) { return (-b*y0 - c) / a; }
};

Line bisector(const Point &a, const Point &b) {
    Line l(a, b);
    Point m = (a+b) / 2;
    swap(l.a, l.b);
    l.b = -l.b;
    l.c = -l.a*m.x - l.b*m.y;
    return l;
}

int intersect(const Line l1, const Line l2, Point &r) {
    r.x = l1.b*l2.c - l2.b*l1.c;
    r.y = l2.a*l1.c - l1.a*l2.c;
    double cc = l1.a*l2.b - l2.a*l1.b;
    if (fabs(cc) < EPS)
        return fabs(r.y)<EPS && fabs(r.x)<EPS ? 2 : 0;
    r.x /= cc;
    r.y /= cc;
    return 1;
}

bool circle3pts(const Point &a, const Point &b, const Point &c, Point &r) {
    return intersect(bisector(a, b), bisector(a, c), r) == 1;
}

// --------------------------------------------------------------------------------------------

double minCoverCircle(Point P[], int n) {
    double cr = 0;
    Point c = P[0];
    for (int i=1; i<n; ++i)
        if (dist2(P[i], c) > cr+EPS) {
            c = P[i]; cr = 0;
            for (int j=0; j<i; ++j)
                if (dist2(P[j], c) > cr+EPS) {
                    c = (P[i] + P[j]) / 2;
                    cr = dist2(P[i], c);
                    for (int k=0; k<j; ++k)
                        if (dist2(P[k], c) > cr+EPS) {
                            circle3pts(P[i], P[j], P[k], c);
                            cr = dist2(P[i], c);
                        }
                }
        }
    return sqrt(cr);
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);

    int n;
    double r;
    Point P[143];
    while (cin >> n && n) {
        for (int i=0; i<n; ++i)
            cin >> P[i];
        cin >> r;
        cout << (minCoverCircle(P, n) <= r
                    ? "The polygon can be packed in the circle.\n"
                    : "There is no way of packing that polygon.\n"
                );
    }
}