目前代码没调出来,不太清楚,就是根据一元三次方程的根表达式计算;
#include<bits/stdc++.h>
#define cirno baka
using namespace std;
typedef double db;
db a,b,c,d;
db p2(db x){return x*x;}
db p3(db x){return x*x*x;}
int main(){
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
complex<double> w;
w={-1/2,sqrt(3)/2};
double p=(3*a*c-p2(b))/(3*p2(a));
double q=(27*p2(a)*d-9*a*b*c+2*p3(b))/(27*p3(a));
db x=(-b)/(3*a);
db y=cbrt((-q)/2+sqrt(p2(q/2)+p3(p/3)));
db z=cbrt((-q)/2-sqrt(p2(q/2)+p3(p/3)));
db x1=x+y+z
db x2=x+w*y+w*w*z;
db x3=x+w*w*y+w*z;
db op[3]={x1,x2,x3};
sort(op,op+3);
printf("%.2lf %.2lf %.2lf",op[0],op[1],op[2]);
return 0;
}