1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <algorithm> 5 #include <vector> 6 #include <cmath> 7 using namespace std; 8 9 const double PI = acos(-1.0); 10 const double EPS = 1e-8; 11 12 double Deg2Rad(double deg){return (deg * PI / 180.0);} 13 double Rad2Deg(double rad){return (rad * 180.0 / PI);} 14 double Sin(double deg){return sin(Deg2Rad(deg));} 15 double Cos(double deg){return cos(Deg2Rad(deg));} 16 double ArcSin(double val){return Rad2Deg(asin(val));} 17 double ArcCos(double val){return Rad2Deg(acos(val));} 18 double Sqrt(double val){return sqrt(val);} 19 20 inline int sgn(double x) { 21 return (x > EPS) - (x < -EPS); 22 } 23 24 inline double sqr(double x) { 25 return x * x; 26 } 27 28 struct Point { 29 double x, y; 30 Point() {} 31 Point(double x, double y): x(x), y(y) {} 32 void read() { 33 scanf("%lf%lf", &x, &y); 34 } 35 double length() const { 36 return sqrt(x * x + y * y); 37 } 38 Point operator + (const Point &rhs) const { 39 return Point(x + rhs.x, y + rhs.y); 40 } 41 Point operator - (const Point &rhs) const { 42 return Point(x - rhs.x, y - rhs.y); 43 } 44 Point operator * (double t) const { 45 return Point(x * t, y * t); 46 } 47 Point operator / (double t) const { 48 return Point(x / t, y / t); 49 } 50 Point unit() const { 51 double l = length(); 52 return *this / l; 53 } 54 double angle() const { 55 return atan2(y, x); 56 } 57 }; 58 59 double dist(const Point &a, const Point &b) { 60 return (a - b).length(); 61 } 62 63 Point rotate(const Point &p, double angle, const Point &o = Point(0, 0)) { 64 Point t = p - o; 65 double x = t.x * cos(angle) - t.y * sin(angle); 66 double y = t.y * cos(angle) + t.x * sin(angle); 67 return Point(x, y) + o; 68 } 69 70 double cross(const Point &a, const Point &b) { 71 return a.x * b.y - a.y * b.x; 72 } 73 74 double cross(const Point &sp, const Point &ep, const Point &op) { 75 return cross(sp - op, ep - op); 76 } 77 78 struct Region { 79 double st, ed; 80 Region() {} 81 Region(double st, double ed): st(st), ed(ed) {} 82 }; 83 84 struct Circle { 85 Point c; 86 double r; 87 Circle() {} 88 Circle(Point c, double r): c(c), r(r) {} 89 void read() { 90 c.read(); 91 scanf("%lf", &r); 92 } 93 double area() const { 94 return PI * r * r; 95 } 96 bool contain(const Circle &rhs) const { 97 return sgn(dist(c, rhs.c) + rhs.r - r) <= 0; 98 } 99 bool contain(const Point &p) const { 100 return sgn(dist(c, p) - r) <= 0; 101 } 102 bool intersect(const Circle &rhs) const { 103 return sgn(dist(c, rhs.c) - r - rhs.r) < 0; 104 } 105 bool tangency(const Circle &rhs) const { 106 return sgn(dist(c, rhs.c) - r - rhs.r) == 0; 107 } 108 Point pos(double angle) const { 109 Point p = Point(c.x + r, c.y); 110 return rotate(p, angle, c); 111 } 112 }; 113 114 void intersection(const Circle &cir1, const Circle &cir2, Point &p1, Point &p2) { 115 double l = dist(cir1.c, cir2.c); 116 double d = (sqr(l) - sqr(cir2.r) + sqr(cir1.r)) / (2 * l); 117 double d2 = sqrt(sqr(cir1.r) - sqr(d)); 118 Point mid = cir1.c + (cir2.c - cir1.c).unit() * d; 119 Point v = rotate(cir2.c - cir1.c, PI / 2).unit() * d2; 120 p1 = mid + v, p2 = mid - v; 121 } 122 123 const int MAXN = 10; 124 125 126 struct Region_vector { 127 int n; 128 Region v[5]; 129 void clear() { 130 n = 0; 131 } 132 void add(const Region &r) { 133 v[n++] = r; 134 } 135 } *last, *cur; 136 137 Circle cir[MAXN]; 138 bool del[MAXN]; 139 double r; 140 int n = 5; 141 142 double CommonArea(const Circle &A, const Circle &B) { 143 double area = 0.0; 144 const Circle & M = (A.r > B.r) ? A : B; 145 const Circle & N = (A.r > B.r) ? B : A; 146 double D = dist(M.c, N.c); 147 if((D < M.r + N.r) && (D > M.r - N.r)) { 148 double cosM = (M.r * M.r + D * D - N.r * N.r) / (2.0 * M.r * D); 149 double cosN = (N.r * N.r + D * D - M.r * M.r) / (2.0 * N.r * D); 150 double alpha = 2.0 * ArcCos(cosM); 151 double beta = 2.0 * ArcCos(cosN); 152 double TM = 0.5 * M.r * M.r * Sin(alpha); 153 double TN = 0.5 * N.r * N.r * Sin(beta); 154 double FM = (alpha / 360.0) * M.area(); 155 double FN = (beta / 360.0) * N.area(); 156 area = FM + FN - TM - TN; 157 } 158 else if(D <= M.r - N.r) { 159 area = N.area(); 160 } 161 return area; 162 } 163 164 bool isOnlyOnePoint() { 165 bool flag = false; 166 Point t; 167 for(int i = 0; i < n; ++i) 168 for(int j = i + 1; j < n; ++j) { 169 if(cir[i].tangency(cir[j])) { 170 flag = true; 171 t = (cir[i].c + cir[j].c) / 2; 172 break; 173 } 174 } 175 if(!flag) return false; 176 for(int i = 0; i < n; ++i) 177 if(!cir[i].contain(t)) return false; 178 printf("Only the point (%.2f, %.2f) is for victory.\n", t.x + EPS, t.y + EPS); 179 return true; 180 } 181 182 bool solve() { 183 if(isOnlyOnePoint()) return true; 184 memset(del, 0, sizeof(del)); 185 for(int i = 0; i < n; ++i) 186 for(int j = 0; j < n; ++j) { 187 if(del[j] || i == j) continue; 188 if(cir[i].contain(cir[j])) { 189 del[i] = true; 190 break; 191 } 192 } 193 double ans = 0; 194 for(int i = 0; i < n; ++i) { 195 if(del[i]) continue; 196 last->clear(); 197 Point p1, p2; 198 for(int j = 0; j < n; ++j) { 199 if(del[j] || i == j) continue; 200 if(!cir[i].intersect(cir[j])) return false; 201 cur->clear(); 202 intersection(cir[i], cir[j], p1, p2); 203 double rs = (p2 - cir[i].c).angle(), rt = (p1 - cir[i].c).angle(); 204 if(sgn(rs) < 0) rs += 2 * PI; 205 if(sgn(rt) < 0) rt += 2 * PI; 206 if(last->n == 0) { 207 if(sgn(rt - rs) < 0) cur->add(Region(rs, 2 * PI)), cur->add(Region(0, rt)); 208 else cur->add(Region(rs, rt)); 209 } else { 210 for(int k = 0; k < last->n; ++k) { 211 if(sgn(rt - rs) < 0) { 212 if(sgn(last->v[k].st - rt) >= 0 && sgn(rs - last->v[k].ed) >= 0) continue; 213 if(sgn(last->v[k].st - rt) < 0) cur->add(Region(last->v[k].st, min(last->v[k].ed, rt))); 214 if(sgn(rs - last->v[k].ed) < 0) cur->add(Region(max(last->v[k].st, rs), last->v[k].ed)); 215 } else { 216 if(sgn(rt - last->v[k].st) <= 0 || sgn(last->v[k].ed - rs) <= 0) continue; 217 cur->add(Region(max(rs, last->v[k].st), min(rt, last->v[k].ed))); 218 } 219 } 220 } 221 swap(last, cur); 222 if(last->n == 0) break; 223 } 224 for(int j = 0; j < last->n; ++j) { 225 p1 = cir[i].pos(last->v[j].st); 226 p2 = cir[i].pos(last->v[j].ed); 227 ans += cross(p1, p2) / 2; 228 double angle = last->v[j].ed - last->v[j].st; 229 ans += 0.5 * sqr(cir[i].r) * (angle - sin(angle)); 230 } 231 } 232 if(sgn(ans) == 0) return false; 233 printf("The total possible area is %.2f.\n", ans + EPS); 234 //printf("%.2f\n", CommonArea(cir[0], cir[4])); 235 return true; 236 } 237 238 int main() { 239 last = new Region_vector, cur = new Region_vector; 240 while(scanf("%lf", &r) != EOF) { 241 Point t; 242 for(int i = 0; i < n; ++i) { 243 t.read(); 244 cir[i] = Circle(t, r); 245 } 246 if(!solve()) puts("Poor iSea, maybe 2012 is coming!"); 247 } 248 }