算法學習-題目-01-洛谷-P1024 一元三次方程求解-2020-5-19
一、題目
輸入格式
一行,44個實數A,B,C,D。
輸出格式
一行,33個實根,並精確到小數點後22位。
輸入輸出樣例
輸入 #1複製
1 -5 -4 20
輸出 #1複製
-2.00 2.00 5.00
二、分析
暴力_零點定理
三、代碼
#include<iostream>
#include <iomanip>
using namespace std;
int main() {
double a,b,c,d,e,f,g,r;//abcd,efg
/*1*/
cin >>a;
cin >>b;
cin >>c;
cin >>d;
/*2*/
for(double x=-100;x<=100;x+=0.001)
{
r=x+0.001;
if((a*x*x*x+b*x*x+c*x+d)*(a*r*r*r+b*r*r+c*r+d)<0)
{
cout.setf(ios::fixed);
/*3*/ cout<<fixed<<setprecision(2)<<x<<" ";
}
}
return 0;
}