Advertisement
Gosunov

Untitled

Oct 5th, 2022
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define all(a) (a).begin(), (a).end()
  4. #define double long double
  5.  
  6. const int maxn = 105;
  7. const double maxc = 10000;
  8. int x[maxn];
  9. int y[maxn];
  10. int c[maxn];
  11.  
  12. int n;
  13.  
  14. double f(double px, double py) {
  15.     double ans = -1e9;
  16.     for (int i = 0; i < n; ++i) {
  17.         double dx = px - x[i];
  18.         double dy = py - y[i];
  19.  
  20.         ans = max(ans, sqrt(dx*dx + dy*dy) * c[i]);
  21.     }
  22.     return ans;
  23. }
  24.  
  25. double fx(double px) {
  26.     double l = -maxc;
  27.     double r =  maxc;
  28.     for (int _ = 0; _ < 300; ++_) {
  29.         double m1 = l + (r - l) / 3;
  30.         double m2 = l + (r - l) / 3 * 2;
  31.  
  32.         double f1 = f(px, m1);
  33.         double f2 = f(px, m2);
  34.         if (f2 >= f1) {
  35.             r = m2;
  36.         } else {
  37.             l = m1;
  38.         }
  39.     }
  40.     return f(px, (r + l) / 2);
  41. }
  42.  
  43. void solve() {
  44.     cin >> n;
  45.     for (int i = 0; i < n; ++i) {
  46.         cin >> x[i] >> y[i] >> c[i];
  47.     }
  48.  
  49.     double l = -maxc;
  50.     double r =  maxc;
  51.     for (int _ = 0; _ < 300; ++_) {
  52.         double m1 = l + (r - l) / 3;
  53.         double m2 = l + (r - l) / 3 * 2;
  54.  
  55.         double f1 = fx(m1);
  56.         double f2 = fx(m2);
  57.         if (f2 >= f1) {
  58.             r = m2;
  59.         } else {
  60.             l = m1;
  61.         }
  62.     }
  63.     cout << fx((r + l) / 2) << '\n';
  64. }
  65.  
  66. signed main() {
  67.     ios::sync_with_stdio(0); cin.tie(0);
  68.     cout.precision(10),cout.setf(ios_base::fixed);
  69.     solve();
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement