Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ld long double
  3. #define EPS 1E-15L
  4. using namespace std;
  5. ld a, b, c, d;
  6. ld f(ld x)
  7. {
  8. return a * x * x * x + b * x * x + c * x + d;
  9. }
  10. int main()
  11. {
  12. cin >> a >> b >> c >> d;
  13. ld l = -1E9L, r = 1E9L;
  14. for (int i = 0; i < 1000; i++)
  15. {
  16. ld m = (l + r) / 2.0L;
  17. if (f(m) < EPS && a > 0)
  18. l = m;
  19. else if (f(m) >= EPS && a > 0)
  20. r = m;
  21. else if (f(m) < EPS && a < 0)
  22. r = m;
  23. else if (f(m) >= EPS && a < 0)
  24. l = m;
  25. }
  26. cout << fixed << setprecision(20) << l << endl;
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement