danielvitor23

Dissonância quadrática

Jul 29th, 2023
1,303
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 1 0
  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define eps 1e-9
  5. #define eq(a, b) (a == b)
  6. #define lt(a, b) (a < b)
  7. using namespace std;
  8.  
  9. using i64 = long long;
  10. using ld = float;
  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.     if (lt(get_hx(-c/2), get_hx(x))) x = -c/2;
  30.  
  31.     cout << x << ' ' << get_hx(x) << '\n';
  32.  
  33.     return 0;
  34.   }
  35.  
  36.   ld x = (ld)(d - b) / (a - c);
  37.  
  38.   if (lt(get_hx(-a/2), get_hx(x))) {
  39.     x = (ld)-a/2;
  40.   }
  41.  
  42.   if (lt(get_hx(-c/2), get_hx(x))) {
  43.     x = (ld)-c/2;
  44.   }
  45.  
  46.   cout << x << ' ' << get_hx(x) << '\n';
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment