File size: 1,472 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
#include <bits/stdc++.h>

typedef double ptype;

using namespace std;

struct Point {
    ptype x, y;
    Point() {}
    Point(ptype x_, ptype y_): x(x_), y(y_) {}
};

int N;
double R;
vector <Point> vert;
Point center;

bool getCenter(Point p1, Point p2) {
    double d2 = pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2);
    double det = R * R / d2 - 0.25;
    if (det < 0.0) return false;
    double h = sqrt(det);
    center.x = (p1.x + p2.x) * 0.5 + (p1.y - p2.y) * h;
    center.y = (p1.y + p2.y) * 0.5 + (p2.x - p1.x) * h;
    return true;
}

bool packed () {
    for (Point p_i: vert) {
        double dis = pow(p_i.x - center.x, 2) + pow(p_i.y - center.y, 2);
        if (dis > R * R) return false;
    }
    return true;
}

bool possible () {
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (getCenter(vert[i], vert[j]) and packed()) return true;
            if (getCenter(vert[j], vert[i]) and packed()) return true;
        }
    }
    return false;
}

bool readCase () {
    scanf("%d", &N);
    if (N == 0) return false;
    vert.resize(N);
    for (int i = 0; i < N; i++) scanf("%lf %lf", &vert[i].x, &vert[i].y);
    scanf("%lf", &R);
    return true;
}

inline void clear () {
    vert.clear();
}

int main () {
    while (readCase()) {
        puts(possible()
            ? "The polygon can be packed in the circle."
            : "There is no way of packing that polygon.");
        clear();
    }
    return (0);
}