Language: C++

#include<cstdio>
#include<vector>
#include<math.h>
using namespace std;
const double ESP = 1e-10;
double add(double x, double y) {
  if (abs(x + y) < ESP * (abs(x) + abs(y)))
    return 0;
  else return x + y;
}
struct P {
  double x, y;
  P() {}
  P(double X, double Y) {
    x = X, y = Y;
  }
  void init(int X, int Y) {
    x = (double) X, y = (double) Y;
  }
  P operator + (P p) {
    return P(add(p.x, x), add(p.y, y));
  }
  P operator - (P p) {
    return P(add(p.x, -x), add(p.y, -y));
  }
  P operator * (double d) {
    return P(x * d, y * d);
  }
  double det(P p) {
    return add(p.x * x, p.y * y);
  }
  double dot(P p) {
    return add(p.y * x, -p.x * y);
  }
  double square() {
    return add(x * x, y * y);
  }
  double size() {
    return sqrt(square());
  }
  P normal() {
    double s = size();
    if (s < ESP) return P(0, 0);
    return P(x / s, y / s);
  }
  P vertical() {
    P t = normal();
    return P(t.y, -t.x);
  }
  void print() {
    printf("P:(%f, %f)\n", x, y);
  }
};

bool plus(double a) {
  return a > ESP;
}
bool minas(double a) {
  return a < -ESP;
}
bool zero(double a) {
  return abs(a) <= ESP;
}

int n, x[10], y[10], l[10];
P dir[10];
double r[10];

int cross(int i, int j) {
  double s = (dir[i] - dir[j]).size();
  //printf("%d:%d,%f,%f,%f\n",i,j,s,r[i],r[j]);
  if (!minas(r[i] - s)) return j; // can everywhere in j
  if (!minas(r[j] - s)) return i; // can everywhere in i
  if (plus(s - r[i] - r[j])) return -2; // imposible
  return -1;
}

bool canClear(P p) {
  //for (int i = 0; i < n; i++) if (ESP < (add((p - dir[i]).square(), -r[i] * r[i])) && 0.1 > (add((p - dir[i]).square(), -r[i] * r[i]))) printf("%d,%f]]]\n",i,(add((p - dir[i]).square(), -r[i] * r[i])));
  for (int i = 0; i < n; i++) if (0.00001 < (add((p - dir[i]).square(), -r[i] * r[i]))) return false;
  return true;
}

double search(double r1, double r2, double ps, double guess, double halfsize) {
  if (r1 < guess || r2 < guess) return search(r1, r2, ps, guess - halfsize, halfsize / 2);
  double t = add(sqrt(r1 * r1 - guess * guess), add(sqrt(r2 * r2 - guess * guess), -ps));
  //printf("%f,%f,%f,%f,%f\n",r1,r2,ps,guess,t);
  if (zero(t)) return guess;
  if (plus(t)) return search(r1, r2, ps, guess + halfsize, halfsize / 2);
  return search(r1, r2, ps, guess - halfsize, halfsize / 2);
}

bool check(double h) {
  for (int i = 0; i < n; i++) {
    if (minas((double)l[i] - h)) return false;
    if (zero((double)l[i] - h)) r[i] = 0.0;
    r[i] = sqrt(add((double)l[i] * l[i],-h * h));
    //printf("r[%d]=%f\n",i,r[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      int t = cross(i, j);
      //printf("t:%d\n",t);
      if (t == -2){ return false;}
      if (t == -1) {
        double l = search(r[i], r[j], (dir[i] - dir[j]).size(), 300.0, 150.0);
        double l1 = sqrt(r[i] * r[i] - l * l);
        double l2 = sqrt(r[j] * r[j] - l * l);
        P ave = (dir[i] * l2 + dir[j] * l1) * (1.0 / (l1 + l2));
        P d = (dir[i] - dir[j]).vertical() * l;
        if (canClear(ave + d)) return true;
        if (canClear(ave - d)) return true;
      }
      if (t >= 0) {
        if (canClear(dir[t])) return true;
      }
    }
  }
  return false;
}

double getH() {
  double lb = 1.0, ub = 300.0;
  while (!zero(ub - lb)) {
    double ave = (lb + ub) / 2;
    if (check(ave)) lb = ave;
    else ub = ave;
    //printf("%f-%f\n",lb,ub);
  }
  return lb;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    for (int i = 0; i < n; i++) scanf("%d%d%d", &x[i], &y[i], &l[i]);
    for (int i = 0; i < n; i++) dir[i].init(x[i], y[i]);
    //printf("%d\n",(int)check(72.2251798));
    //printf("%d\n",(int)check(71.954102));
    if (n == 1) printf("%f\n", (double)l[0]);
    else printf("%f\n", getH());
  }
}



Compiler output:
a.cc: In function 'int cross(int, int)':
a.cc:74:7: error: reference to 'plus' is ambiguous
   74 |   if (plus(s - r[i] - r[j])) return -2; // imposible
      |       ^~~~
In file included from /usr/include/c++/14/bits/refwrap.h:39,
                 from /usr/include/c++/14/vector:68,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:55:6: note:                 'bool plus(double)'
   55 | bool plus(double a) {
      |      ^~~~
a.cc: In function 'double search(double, double, double, double, double)':
a.cc:89:7: error: reference to 'plus' is ambiguous
   89 |   if (plus(t)) return search(r1, r2, ps, guess + halfsize, halfsize / 2);
      |       ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:55:6: note:                 'bool plus(double)'
   55 | bool plus(double a) {
      |      ^~~~