danielvitor23

Dissonância quadrática

Jul 29th, 2023
1,255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define eps 1e-9
  5. #define eq(a, b) (abs(a - b) < eps)
  6. #define lt(a, b) (a < b - eps)
  7. using namespace std;
  8.  
  9. using i64 = long long;
  10. using ld = long double;
  11.  
  12. ld a, b, c, d;
  13.  
  14. ld get_hx(ld x) {
  15.   return max(
  16.     x * x + a * x + b,
  17.     x * x + c * x + d
  18.   );
  19. }
  20.  
  21. int main() {
  22.   cin.tie(0)->sync_with_stdio(0);
  23.  
  24.   cin >> a >> b >> c >> d;
  25.  
  26.   if (eq(a, c)) {
  27.     ld x = (ld)-a/2;
  28.  
  29.     cout << fixed << setprecision(10) << x << ' ' << get_hx(x) << '\n';
  30.  
  31.     return 0;
  32.   }
  33.  
  34.   ld x = (ld)(d - b) / (a - c);
  35.  
  36.   if (lt(get_hx(-a/2), get_hx(x))) {
  37.     x = (ld)-a/2;
  38.   }
  39.  
  40.   if (lt(get_hx(-c/2), get_hx(x))) {
  41.     x = (ld)-c/2;
  42.   }
  43.  
  44.   cout << fixed << setprecision(10) << x << ' ' << get_hx(x) << '\n';
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment