fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define ld long double
  7. #define vll vector<ll>
  8. #define pb push_back
  9. #define f first
  10. #define se second
  11. #define endl '\n'
  12. #define Left Node << 1
  13. #define Right Node << 1 | 1
  14. #define INF -1e9
  15. #define Fast() {ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
  16.  
  17. struct Point {
  18. ld x, y;
  19. };
  20.  
  21.  
  22. void solve()
  23. {
  24. int n;
  25. cin >> n;
  26.  
  27. vector<Point> a(n);
  28. for (auto &[x, y] : a)
  29. cin >> x >> y;
  30.  
  31. int side = (a[0].y > 0 ? 1 : -1);
  32. for (const auto &p : a) {
  33. if ((p.y > 0 ? 1 : -1) != side) {
  34. cout << -1 << endl;
  35. return;
  36. }
  37. }
  38.  
  39. auto check = [&](ld r) {
  40. ld left = -1e30;
  41. ld right = 1e30;
  42.  
  43. for (auto [x, y] : a) {
  44. y = fabsl(y);
  45. ld v = 2 * r * y - y * y;
  46.  
  47. if (v < 0)
  48. return false;
  49.  
  50. ld d = sqrtl(v);
  51.  
  52. left = max(left, x - d);
  53. right = min(right, x + d);
  54.  
  55. if (left > right)
  56. return false;
  57. }
  58.  
  59. return true;
  60. };
  61.  
  62. ld l = 0, r = 1e18;
  63. for (int it = 0; it < 100; it++) {
  64. ld mid = (l + r) / 2;
  65.  
  66. if (check(mid))
  67. r = mid;
  68. else
  69. l = mid;
  70. }
  71.  
  72. cout << fixed << setprecision(10) << (double)r << endl;
  73. }
  74.  
  75. int main()
  76. {
  77. Fast();
  78.  
  79. int t = 1;
  80. // cin >> t;
  81. while (t--)
  82. {
  83. solve();
  84. }
  85.  
  86. return 0;
  87. }
Success #stdin #stdout 0.04s 5320KB
stdin
Standard input is empty
stdout
0.0000000000