#include #include #include #include #include using namespace std; #define EPS 1e-6 int main() { int n; cin >> n; vector x(n); vector y(n); vector d(n); for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i] >> d[i]; // Add some epsilon to make sure none of the circles overlap with the origin. x[i] += EPS; y[i] += EPS; } set> cands; // Consider intersections between circles. for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { double dd = hypot(x[i] - x[j], y[i] - y[j]); double ex = (x[j] - x[i]) / dd; double ey = (y[j] - y[i]) / dd; double xx = (d[i] * d[i] - d[j] * d[j] + dd * dd) / (2 * dd); if (d[i] * d[i] - xx * xx >= 0) { double yy = sqrt(d[i] * d[i] - xx * xx); cands.insert(make_pair(x[i] + xx * ex - yy * ey, y[i] + xx * ey + yy * ex)); cands.insert(make_pair(x[i] + xx * ex + yy * ey, y[i] + xx * ey - yy * ex)); } } // Intersections of (0,0) - (x[i], y[i]) line with circle. if (y[i] != 0) { double k = 1.0 * x[i] / y[i]; double a = k*k + 1; double b = -2 * (k*x[i] + y[i]); double c = x[i] * x[i] + y[i] * y[i] - d[i] * d[i]; double y1 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a); double y2 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a); cands.insert(make_pair(k * y1, y1)); cands.insert(make_pair(k * y2, y2)); } else if (x[i] != 0) { double k = 1.0 * y[i] / x[i]; double a = k*k + 1; double b = -2 * (k*y[i] + x[i]); double c = y[i] * y[i] + x[i] * x[i] - d[i] * d[i]; double x1 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a); double x2 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a); cands.insert(make_pair(x1, k * x1)); cands.insert(make_pair(x2, k * x2)); } } cout.setf(ios::fixed,ios::floatfield); cout.precision(3); // A set of circles that don't overlap. if (cands.empty()) { sort(d.begin(), d.end()); cout << 1.0 * d[0] << endl; return 0; } double max_dist = 0; for (auto point : cands) { bool ok = true; for (int i = 0; i < n && ok; ++i) { if (sqrt((x[i] - point.first) * (x[i] - point.first) + (y[i] - point.second) * (y[i] - point.second)) > d[i] + EPS) { ok = false; } } if (ok) { max_dist = max(max_dist, sqrt(point.first * point.first + point.second * point.second)); } } cout << max_dist << endl; }