Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- double good(int a, int b, int c, int d, double mid){
- return a * mid * mid * mid + b * mid * mid + c * mid + d;
- }
- double bin(int a, int b, int c, int d){
- double left = -1e9, right = 1e9, mid;
- while(left + 1e-5 < right){
- mid = (left + right) / 2;
- if (good(a, b, c, d, mid) <= 0)
- left = mid;
- else
- right = mid;
- }
- return (left + right) / 2;
- }
- int main (){
- int a, b, c, d;
- std::cin >> a >> b >> c >> d;
- if (a < 0){
- a = -a;
- b = -b;
- c = -c;
- d = -d;
- }
- std::cout << std::setprecision(10) << bin(a, b, c , d);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment