Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define double long double
- int a , b , c , d;
- double f(double x , int a , int b , int c , int d){
- double s = a * x * x * x + b * x * x + c * x + d;
- return s;
- }
- signed main()
- {
- cout.precision(6);
- cin >> a >> b >> c >> d;
- double r = 1.0;
- while(true){
- if((f(r , a , b , c , d) * f(-r , a , b , c , d)) < 0){
- break;
- }else{
- r *= 2;
- }
- }
- double l = -r;
- while((l + 1e-6) <= r){
- double m = (l + r) * 1.0 / 2;
- if((f(m , a , b , c , d) * f(-m , a , b , c , d)) < 0){
- r = m;
- }else{
- l = m;
- }
- }
- double x = abs(f(l , a , b , c , d)) , y = abs(f(-l , a , b , c , d));
- if(x > y)
- l = -l;
- cout << fixed << l << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement