ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#206384 | #1745. 一元三次方程求解 | kevin0625 | 100 | 1ms | 1288kb | C++11 | 503b | 2024-07-22 17:33:36 | 2024-07-22 20:00:31 |
answer
#include <iostream>
using namespace std;
double a,b,c,d;
double f(double x)
{
return x * x * x * a + x * x * b + x * c + d;
}
int main()
{
cin >> a >> b >> c >> d;
double x1, x2, xx;
for(double x = -100; x <= 100; ++x)
{
x1 = x, x2 = x + 1;
if(f(x1) == 0) printf("%.2f ", x1);
else if(f(x1) * f(x2) < 0)
{
while(x2 - x1 >= 0.001)
{
xx = (x2 + x1) / 2;
if(f(x1) * f(xx) <= 0)
x2 = xx;
else
x1 = xx;
}
printf("%.2f ", x1);
}
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 25
Accepted
time: 1ms
memory: 1280kb
input:
1 -2 -1 2
output:
-1.00 1.00 2.00
result:
ok single line: '-1.00 1.00 2.00 '
Test #2:
score: 25
Accepted
time: 0ms
memory: 1288kb
input:
1 -4.65 2.25 1.4
output:
-0.35 1.00 4.00
result:
ok single line: '-0.35 1.00 4.00 '
Test #3:
score: 25
Accepted
time: 0ms
memory: 1288kb
input:
1 10 -1 -10
output:
-10.00 -1.00 1.00
result:
ok single line: '-10.00 -1.00 1.00 '
Test #4:
score: 25
Accepted
time: 0ms
memory: 1284kb
input:
1 -1.8 -8.59 -0.84
output:
-2.10 -0.10 4.00
result:
ok single line: '-2.10 -0.10 4.00 '