You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
//本题目是浮点数二分的板子题
const double eps = 1e-8 ;
double a , B , c , d ;
//方程
double f ( double x ) { return a * x * x * x + b * x * x + c * x + d ; }
int main ( ) {
//输入
cin > > a > > b > > c > > d ;
double x , y , mid ;
for ( int i = - 100 ; i < = 100 ; i + + ) {
x = i , y = i + 1 ; //左右边界,循环尝试每一个可能的边界, 因为题目中说了, 每两个解之间的差是不小1的
//边界
if ( f ( x ) = = 0 ) {
printf ( " %.2f " , x ) ; //如果符合条件则直接输出
continue ;
}
//如果其中有解就开始二分
if ( f ( x ) * f ( y ) < 0 ) { //题目中有提示
//精度要求
while ( y - x > = eps ) {
mid = ( x + y ) / 2 ;
if ( f ( x ) * f ( mid ) < = 0 )
y = mid ; //判断解在哪个区间
else
x = mid ;
}
printf ( " %.2f " , x ) ;
}
}
return 0 ;
}