Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
136944 | 梁乃元 | 解一元三次方程 | C++ | 通过 | 100 | 0 MS | 244 KB | 678 | 2024-03-09 16:24:27 |
# include <bits/stdc++.h> using namespace std ; double a , b , c , d ; long double f ( double x ) { return a * x * x * x + b * x * x + c * x + d ; } int main ( ) { cin >> a >> b >> c >> d ; for ( double i = -100 ; i <= 100 ; i ++ ) { double x1 = i , x2 = i + 1 ; if ( f ( x1 ) == 0 ) { cout << fixed << setprecision ( 2 ) << x1 << ' ' ; } else if ( f ( x1 ) * f ( x2 ) < 0 ) { while ( x2 - x1 >= 0.001 ) { double xx = ( x1 + x2 ) / 2 ; if ( f ( x1 ) * f ( xx ) <= 0 ) { x2 = xx ; } else { x1 = xx ; } } cout << fixed << setprecision ( 2 ) << x1 << ' ' ; } } return 0 ; }