Help!xxs求助
查看原帖
Help!xxs求助
464142
Executor_Dragon楼主2023/7/15 10:58

公式应该没错,求调

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
 	double x1,x2,x3;
 	cin>>a>>b>>c>>d;
 	double A=b*b-3*a*c;
 	double B=b*c-9*a*d;
 	double C=c*c-3*b*d;
 	double T=(2*A*b-3*a*B)/sqrt(A*A*A);
 	double theta=acos(T);
 	x1=(-b+2*sqrt(A)*cos(theta/3))/(3*a);
 	x2=(-b+sqrt(A)*(cos(theta/3)+sqrt(3)*sin(theta/3)))/(3*a);
 	x2=(-b+sqrt(A)*(cos(theta/3)-sqrt(3)*sin(theta/3)))/(3*a);
 	printf("%.2lf %.2lf %.2lf",x1,x2,x3);
}

INPUT:

1 -5 -4 20

OUTPUT:

5.47 2.35 0.00
2023/7/15 10:58
加载中...