比赛 |
普及组水题赛(语言题赛) |
评测结果 |
AAAAA |
题目名称 |
一元三次方程求解 |
最终得分 |
100 |
用户昵称 |
JSX |
运行时间 |
0.008 s |
代码语言 |
C++ |
内存使用 |
0.23 MiB |
提交时间 |
2014-10-14 18:01:10 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <algorithm>
using namespace std;
double a,b,c,d,x,x1,x2,x3;
double F(double x){
return ((a*x+b)*x+c)*x+d;
}
/*#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <algorithm>
typedef long long LL;
const double EPS = 1e-11;
#define MAXN 100005
using namespace std;
inline int L(int x){ return (x<<1); }
inline int R(int x){ return (x<<1)+1; }
int M=0;
LL Sum[MAXN<<2]={0},Add[MAXN<<2]={0};
int s=0,t=0,v=0;
void PushUp(int x){
Sum[x]=Sum[L(x)]+Sum[R(x)];
}
void BuildTree(int n){
for(M=1;M<n+2;M<<=1);
for(int i=1;i<=n;++i) scanf("%lld",&Sum[i+M]);
for(int i=M-1;i>0;--i) PushUp(i);
}
void PushDown(int x,int l){
if(Add[x]!=0){
Add[L(x)]+=Add[x]; Add[R(x)]+=Add[x];
Sum[L(x)]+=Add[x]*(l-(l>>1));
Sum[R(x)]+=Add[x]*(l>>1);
Add[x]=0;
}
}
void UpData(int l,int r,int x){
if(s<=l && r<=t){
Add[x]+=v; Sum[x]+=v*(r-l+1); return;
}
PushDown(x,r-l+1);
int Mid=(l+r)>>1;
if(s<=Mid) UpData(l,Mid,L(x));
if(t>Mid ) UpData(Mid+1,r,R(x));
PushUp(x);
}
LL Query(int l,int r,int x){
if(s<=l && r<=t){
return Sum[x];
}
int Mid=(l+r)>>1;
LL Ans=0;
if(s<=Mid) Ans+=Query(l,Mid,L(x));
if(t> Mid) Ans+=Query(Mid+1,r,R(x));
return Ans;
}
int main(){
//freopen("","r",stdin);
//freopen("","w",stdout);
int N,K=0;
scanf("%d %d",&N,&K);
//printf("%d\n",K);
BuildTree(N);
while(K--){
char c; int a,b,d;
scanf("%s",&c);
if(c=='Q'){
scanf("%d%d",&a,&b);
s=a; t=b;
printf("%lld\n",Query(1,M,1));
}
else{
scanf("%d%d%d",&a,&b,&d);
s=a; t=b; v=d;
UpData(1,M,1);
}
}
while(1);
fclose(stdin);
fclose(stdout);
return 0;
}*/
int main(){
freopen("3cfc.in","r",stdin);
freopen("3cfc.out","w",stdout);
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
for(double i=-100;i<=100;i++){
x1=i;
x2=i+1;
if(F(x1)==0) printf("%.2f ",x1);
if((F(x1))*(F(x2))<0){
while(x2-x1>=0.001){
x3=(x2+x1)/2;
if((F(x1))*(F(x3))<=0) x2=x3;
else x1=x3;
}
printf("%.2f ",x1);
}
}
}