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