1 条题解
-
0
C++ :
#include<cstring> #include<cstdio> using namespace std; double ans[4]; double a,b,c,d; double f(double xt) { double s; s=xt*xt*xt+b*xt*xt+c*xt+d; return s; } int main() { scanf("%lf%lf%lf%lf",&a,&b,&c,&d); b/=a; c/=a; d/=a; double x1,x2; int p=0; for (int x=-10000;x<=10000;x++) { x1=(x-0.05)/100.0; x2=(x+0.05)/100.0; if (f(x/100.0)==0 || f(x1)*f(x2)<0) { p++; ans[p]=x/100.0; } if (p==3) break; } for (int i=1;i<=2;i++) for (int j=2;j<=3;j++) if (ans[i]>ans[j]) { double t=ans[i];ans[i]=ans[j];ans[j]=t; } for (int i=1;i<=p-1;i++) printf("%.2lf ",ans[i]); printf("%0.2lf",ans[p]); return 0; }
Pascal :
var a,b,c,d,x,tmp:real; ansx,f:array[1..3] of real; i,j:integer; begin readln(a,b,c,d); for i:=1 to 3 do f[i]:=1e12; x:=-100; while(x<=100) do begin tmp:=(d+x*(c+x*(b+x*a))); j:=1; for i:=2 to 3 do if (f[i]>f[j]) then j:=i; if (abs(tmp)<f[j]) then begin f[j]:=abs(tmp); ansx[j]:=x; end; x:=x+0.01; end; for i:=1 to 3 do for j:=i+1 to 3 do if (ansx[i]>ansx[j]) then begin tmp:=ansx[i]; ansx[i]:=ansx[j]; ansx[j]:=tmp; end; writeln(ansx[1]:0:2,' ',ansx[2]:0:2,' ',ansx[3]:0:2); end.
- 1
信息
- ID
- 211
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者