Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ld long double
- #define EPS 1E-15L
- using namespace std;
- ld a, b, c, d;
- ld f(ld x)
- {
- return a * x * x * x + b * x * x + c * x + d;
- }
- int main()
- {
- cin >> a >> b >> c >> d;
- ld l = -1E9L, r = 1E9L;
- for (int i = 0; i < 1000; i++)
- {
- ld m = (l + r) / 2.0L;
- if (f(m) < EPS && a > 0)
- l = m;
- else if (f(m) >= EPS && a > 0)
- r = m;
- else if (f(m) < EPS && a < 0)
- r = m;
- else if (f(m) >= EPS && a < 0)
- l = m;
- }
- cout << fixed << setprecision(20) << l << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement