50分的同学看看这里

P1024 [NOIP2001 提高组] 一元三次方程求解

好吧
by ⚡GG⚡ @ 2018-05-25 22:06:26


@[LiuChenxuan](/space/show?uid=51049) 但我的是double呀! ```cpp #include<bits/stdc++.h> using namespace std; /*看这儿→→→*/double a,b,c,d; double j[4]={0}; double f(double x) { return (x*x*x*a+b*x*x+x*c+d); } int main() { double x,x1,x2,xx; int i=1; cin>>a>>b>>c>>d; for(x=-100;x<=100;x++) { x1=x;x2=x+1; if(f(x1)==0){ j[i]=x1; i++; } else if(f(x1)*f(x2)<0) { while(x2-x1>=0.001) { xx=(x2+x1)/2; if(f(x1)*f(x2)<=0) x2=xx; else x1=xx; } j[i]=x1; i++; } } for(i=1;i<=3;i++) printf("%.2lf ",j[i]); return 0; } ```
by ⚡GG⚡ @ 2018-05-27 21:21:11


|