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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
| #include <bits/stdc++.h>
using namespace std;
#define endl "\n" using ll = long long; using db = double;
const int N = 110; const db eps = 1e-11;
int sgn(db x) { if (fabs(x) < eps) return 0; else return x > 0 ? 1 : -1; }
struct Point { db x, y;
Point() {} Point(db _x, db _y) { x = _x, y = _y; } db len() { return hypot(x, y); } db distance(Point &other) { return hypot(x - other.x, y - other.y); } Point operator+(const Point &other) const { return {x + other.x, y + other.y}; } Point operator-(const Point &other) const { return {x - other.x, y - other.y}; } Point trunc(db r) { db l = len(); if (!sgn(l)) { return *this; } r /= l; return {x * r, y * r}; } Point rotright() { return {-y, x}; } Point rotleft() { return {y, -x}; } Point change() { return {-x, -y}; }
};
struct Circle { Point p; db r;
void input() { scanf("%lf %lf %lf", &p.x, &p.y, &r); } Circle() {} Circle(Point _p, db _r) { p = _p, r = _r; } Circle(db _x, db _y, db _r) { p = Point(_x, _y); r = _r; } int relationcicle(Circle v) { db d = p.distance(v.p); if (sgn(d - r - v.r) > 0) return 5; if (sgn(d - r - v.r) == 0) return 4; db l = fabs(r - v.r); if (sgn(d - r - v.r) < 0 && sgn(d - l) > 0) return 3; if (sgn(d - l) == 0) return 2; else return 1; } int pointcrosscircle(Circle v, Point &p1, Point &p2) { int rel = relationcicle(v); if (rel == 1 || rel == 5) return 0; db d = p.distance(v.p); db l = (d * d + r * r - v.r * v.r) / (2 * d); db h = sqrt(r * r - l * l); Point tmp = p + (v.p - p).trunc(l); p1 = tmp + ((v.p - p).rotleft().trunc(h)); p2 = tmp + ((v.p - p).rotright().trunc(h)); if (rel == 2 || rel == 4) { return 1; } return 2; }
} o, a[N];
int n; db r; vector<Point> vec;
void gao(Circle tmp) { Point p[2]; int res = o.pointcrosscircle(tmp, p[0], p[1]); for (int i = 0; i < res; ++i) { vec.push_back(p[i]); } }
bool check() { for (auto p : vec) { p = p.change(); bool F = true; for (int i = 1; i <= n; ++i) { db dis = p.distance(a[i].p); if (sgn(dis - a[i].r) < 0) { F = false; break; } } if (F) { return true; } } return false; }
void RUN() { vec.clear(); scanf("%d %lf", &n, &r); o = Circle(0.0, 0.0, r); for (int i = 1; i <= n; ++i) { a[i].input(); gao(a[i]); } db res = 0; for (int i = 0, len = vec.size(); i < len; ++i) { for (int j = i + 1; j < len; ++j) { res = max(res, vec[i].distance(vec[j])); } } if (check()) { res = 2 * r; } printf("%.15f\n", res); }
int main() { #ifdef LOCAL_JUDGE freopen("input.txt", "r", stdin); #endif
int _T; scanf("%d", &_T); for (int cas = 1; cas <= _T; ++cas) { printf("Case #%d: ", cas); RUN(); }
#ifdef LOCAL_JUDGE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
|