Created
July 12, 2013 13:58
-
-
Save not522/5984663 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<complex> | |
#include<cstdio> | |
using namespace std; | |
#define rep(i, n) for (int i = 0; i < int(n); ++i) | |
typedef long double D; | |
typedef complex<D> P; | |
struct L{P a, b;}; | |
#define X real() | |
#define Y imag() | |
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;} | |
P vec(L a) {return a.b - a.a;} | |
P pLL(L a, L b) {return a.a + vec(a) * (det(vec(b), b.a - a.a) / det(vec(b), vec(a)));} | |
int n; | |
P pp[11]; | |
D l[11]; | |
const D EPS = 1e-8; | |
D mysr(D a) {return sqrt(max(a, (D)0));} | |
bool can(P p, D h) { | |
rep (i, n) { | |
if (mysr(norm(p - pp[i]) + pow(h, 2)) > l[i] + EPS) { | |
return false; | |
} | |
} | |
return true; | |
} | |
int main() { | |
while (true) { | |
cin >> n; | |
if (n == 0) break; | |
rep (i, n) { | |
cin >> pp[i].X >> pp[i].Y >> l[i]; | |
} | |
D res = 0; | |
rep (i, n) rep (j, i) { | |
D theta = acos((pow(l[i], 2) + norm(pp[i] - pp[j]) - pow(l[j], 2)) / (2 * l[i] * abs(pp[i] - pp[j]))); | |
P btm = pp[i] + (pp[j] - pp[i]) / abs(pp[j] - pp[i]) * l[i] * cos(theta); | |
D h = l[i] * sin(theta); | |
if (can(btm, h)) res = max(res, h); | |
} | |
rep (i, n) { | |
if (can(pp[i], l[i])) res = max(res, l[i]); | |
} | |
rep (i, n) rep (j, i) rep (k, j) { | |
D theta1 = acos((pow(l[i], 2) + norm(pp[i] - pp[j]) - pow(l[j], 2)) / (2 * l[i] * abs(pp[i] - pp[j]))); | |
P btm1 = pp[i] + (pp[j] - pp[i]) / abs(pp[j] - pp[i]) * l[i] * cos(theta1); | |
D theta2 = acos((pow(l[i], 2) + norm(pp[i] - pp[k]) - pow(l[k], 2)) / (2 * l[i] * abs(pp[i] - pp[k]))); | |
P btm2 = pp[i] + (pp[k] - pp[i]) / abs(pp[k] - pp[i]) * l[i] * cos(theta2); | |
L l1 = (L){btm1, btm1 + (pp[i] - pp[j]) * P(0, 1)}; | |
L l2 = (L){btm2, btm2 + (pp[i] - pp[k]) * P(0, 1)}; | |
P ppp = pLL(l1, l2); | |
if (!can(ppp, 0)) continue; | |
D h = mysr(l[i] * l[i] - norm(pp[i] - ppp)); | |
if (can(ppp, h)) res = max(res, h); | |
} | |
printf("%.12Lf\n", res); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment