比赛 普及组水题赛(语言题赛) 评测结果 AAAAA
题目名称 一元三次方程求解 最终得分 100
用户昵称 雪狼 运行时间 0.001 s
代码语言 C++ 内存使用 0.31 MiB
提交时间 2014-10-14 19:14:07
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. #define REP(i,a,b) for(int i=a;i!=b+1;++i)
  7. #define CLR(c,x) memset(c,x,sizeof(c))
  8. #define maxn 1000+10
  9. #define eps 1e-9
  10. using namespace std;
  11.  
  12. void setIO(string s){
  13. string in=s+".in",out=s+".out";
  14. freopen(in.c_str(),"r",stdin);
  15. freopen(out.c_str(),"w",stdout);
  16. }
  17.  
  18. double a,b,c,d;
  19.  
  20. double f(double x){
  21. return a*x*x*x+b*x*x+c*x+d;
  22. }
  23.  
  24. int main(){
  25. setIO("3cfc");
  26. scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
  27. REP(i,-100,100){
  28. double L=i+eps,R=i+1+eps;
  29. if(f(L)*f(R)>0)continue;
  30. while(R-L>eps){
  31. double mid=(L+R)/2;
  32. if(f(mid)*f(L)<0)R=mid;
  33. else L=mid;
  34. }
  35. printf("%.2lf ",L);
  36. }
  37. return 0;
  38. }