Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
137014 江婉儿 解一元三次方程 C++ 通过 100 0 MS 244 KB 538 2024-03-09 16:56:18

Tests(6/6):


#include<bits/stdc++.h> using namespace std; double a,b,c,d,ans[5]; int now; double f(double x) { return a*x*x*x+b*x*x+c*x+d; } void sou(double start,double end) { if(now>3||start>end||f(start)*f(end)>0&&end-start<1) return; double mid=(start+end)/2; if(fabs(f(mid))<1e-4) { ans[++now]=mid; sou(start,mid-1); sou(mid+1,end); } else { sou(start,mid); sou(mid,end); } } int main() { cin>>a>>b>>c>>d; sou(-100,100); sort(ans+1,ans+4); printf("%.2lf %.2lf %.2lf",ans[1],ans[2],ans[3]); }


测评信息: