fork download
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <complex>
  4. #include <vector>
  5. #include <utility>
  6. #include <algorithm>
  7. #include <cassert>
  8. #include <queue>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <map>
  13. using namespace std;
  14.  
  15. #define rep(i, n) for (int i = 0; i < (int)(n); i++)
  16.  
  17. int R, N;
  18.  
  19. int main() {
  20. for (;;) {
  21. cin >> R >> N;
  22. if (R == 0 && N == 0) return 0;
  23.  
  24. map<int, int> hmax;
  25.  
  26. rep (i, N) {
  27. int x1, x2, h;
  28. cin >> x1 >> x2 >> h;
  29. for (int x = x1; x < x2; ++x) hmax[x] = max(hmax[x], h);
  30. }
  31.  
  32. double ans = 1E30;
  33. for (int x0 = -R; x0 < R; ++x0) {
  34. int h = hmax[x0];
  35. for (int x = x0; x <= x0 + 1; ++x) {
  36. ans = min(ans, h - sqrt(R * R - x * x) + R);
  37. }
  38. }
  39. printf("%.10f\n", ans);
  40. }
  41. }
  42.  
Success #stdin #stdout 0s 3480KB
stdin
2 3
-2 -1 3
0 1 3
2 3 3
2 2
-2 0 4
0 2 3
2 6
-3 3 1
-2 3 2
-1 3 3
0 3 4
1 3 5
2 3 6
2 6
-3 3 1
-3 2 2
-3 1 3
-3 0 4
-3 -1 5
-3 -2 6
0 0
stdout
0.0000000000
3.0000000000
2.2679491924
2.2679491924