Description
有形如:��3+��2+��+�=0ax3+bx2+cx+d=0 这样的一个一元三次方程。给出该方程中各项的系数(�,�,�,�a,b,c,d 均为实数),并约定该方程存在三个不同实根(根的范围在 −100−100 至 100100 之间),且根与根之差的绝对值 ≥1≥1。要求由小到大依次在同一行输出这三个实根(根与根之间留有空格),并精确到小数点后 22 位。
提示:记方程 �(�)=0f(x)=0,若存在 22 个数 �1x1 和 �2x2,且 �1<�2x1<x2,�(�1)×�(�2)<0f(x1)×f(x2)<0,则在 (�1,�2)(x1,x2) 之间一定有一个根。
Input
一行,44 个实数 �,�,�,�a,b,c,d。
Output
一行,33 个实根,从小到大输出,并精确到小数点后 22 位。
Sample 1
Inputcopy | Outputcopy |
---|---|
1 -5 -4 20 | -2.00 2.00 5.00 |
#include <iostream>
#include <algorithm>
#include<iomanip>
#define endl '\n'
#define ll long long
#define int ll
using namespace std;
const int N = 1e6 + 7;
double a,b,c,d;
double solve(double x)
{
return a*x*x*x+b*x*x+c*x+d;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>a>>b>>c>>d;
for(double i=-100.00;i<=100.00;i+=0.001)
{
if(solve(i)*solve(i+0.001)<0)
{
cout<<setprecision(2)<<fixed<<i<<' ';
i+=1-0.001;
}
}
cout<<endl;
return 0;
}