SDNU 1416.一元三次方程求解(数学)
Description
有形如:ax3+bx2+cx+d=0 这样的一个一元三次方程。给出该方程中各项的系数(a,b,c,d 均为实数),并约定该方程存在三个不同实根(根的范围在-100至100之间),且根与根之差的绝对值> =1。要求三个实根。
Input
四个实数:a,b,c,d
Output
由小到大依次在同一行输出这三个实根(根与根之间留有空格),并精确到小数点后2位
Sample Input
1 -5 -4 20
Sample Output
-2.00 2.00 5.00
Hint
数据规模和约定
|a|,|b|,|c|,|d|< =10
1.盛金公式
一元三次方程aX3+bX2+cX+d=0,(a,b,c,d∈R,且a≠0)
重根判别式
![](https://gss2.bdstatic.com/9fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D102/sign=ab2331cc34d3d539c53d0bc30886e927/4ec2d5628535e5dd85d8b4ed74c6a7efce1b620f.jpg)
总判别式Δ=B2-4AC。
当A=B=0时,
盛金公式1:
![](https://gss0.bdstatic.com/94o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D225/sign=675525ce0b55b31998f9857776ab8286/03087bf40ad162d93a450bd310dfa9ec8b13cd52.jpg)
盛金公式2:
![](https://gss2.bdstatic.com/9fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D163/sign=32fe59ee56e736d15c13880ea8514ffc/810a19d8bc3eb135b90aa089a41ea8d3fd1f4436.jpg)
![](https://gss1.bdstatic.com/-vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D311/sign=5d2a1209347adab439d01d42bad4b36b/6c224f4a20a44623acc404439a22720e0cf3d781.jpg)
盛金公式2的三角式:
![](https://gss2.bdstatic.com/9fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D163/sign=32fe59ee56e736d15c13880ea8514ffc/810a19d8bc3eb135b90aa089a41ea8d3fd1f4436.jpg)
![](https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D381/sign=8acca4efa964034f0bcdc40e9ec37980/6f061d950a7b0208bac355d360d9f2d3572cc8fe.jpg)
其中
,
。
![](https://gss2.bdstatic.com/9fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D234/sign=9d0958c90846f21fcd345950c2256b31/a044ad345982b2b79a612ff633adcbef76099b01.jpg)
![](https://gss0.bdstatic.com/-4o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D48/sign=f35a3d158882b90139adc23b728da7dd/e850352ac65c10386fe5d8f0b0119313b07e896c.jpg)
当Δ=B2-4AC=0时,
盛金公式3:
![](https://gss2.bdstatic.com/9fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D93/sign=e67e7add8fb1cb133a693010dc540b8a/024f78f0f736afc3abe72e57b119ebc4b745121c.jpg)
![](https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D106/sign=0280a396a6c27d1ea1263fc42dd4adaf/78310a55b319ebc461fa67ab8026cffc1e171605.jpg)
其中
。
![](https://gss1.bdstatic.com/-vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D102/sign=03282cf59252982201333dc3e5ca7b3b/0dd7912397dda144e83f7c80b0b7d0a20cf486c9.jpg)
当Δ=B2-4AC<0时,
盛金公式4:
![](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D152/sign=a67c1e10b11bb0518b24b72d047ada77/54fbb2fb43166d22404107a6442309f79052d2c9.jpg)
![](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D241/sign=a6d41e10b11bb0518b24b42c077bda77/54fbb2fb43166d2240e907a6442309f79052d261.jpg)
其中
,
(A>0,-1<T<1)。
![](https://gss2.bdstatic.com/9fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D86/sign=bbf1ffee0afa513d55aa61d83d6d9937/e4dde71190ef76c68d9191199f16fdfaaf516744.jpg)
![](https://gss0.bdstatic.com/94o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D104/sign=285319210bf79052eb1f433e38f2d738/b17eca8065380cd799d4c8dfa344ad345982813d.jpg)
2.盛金判别法
当A=B=0时,方程有一个三重实根。
当Δ=B2-4AC>0时,方程有一个实根和一对共轭虚根。
当Δ=B2-4AC=0时,方程有三个实根,其中有一个二重根。
当Δ=B2-4AC<0时,方程有三个不相等的实根。
3.盛金定理
当b=0,c=0时,盛金公式1无意义;当A=0时,盛金公式3无意义;当A≤0时,盛金公式4无意义;当T<-1或T>1时,盛金公式4无意义。
当b=0,c=0时,盛金公式1是否成立?盛金公式3与盛金公式4是否存在A≤0的值?盛金公式4是否存在T<-1或T>1的值?盛金定理给出如下回答:
盛金定理1:当A=B=0时,若b=0,则必定有c=d=0(此时,方程有一个三重实根0,盛金公式1仍成立)。
盛金定理2:当A=B=0时,若b≠0,则必定有c≠0(此时,适用盛金公式1解题)。
盛金定理3:当A=B=0时,则必定有C=0(此时,适用盛金公式1解题)。
盛金定理4:当A=0时,若B≠0,则必定有Δ>0(此时,适用盛金公式2解题)。
盛金定理5:当A<0时,则必定有Δ>0(此时,适用盛金公式2解题)。
盛金定理6:当Δ=0时,若A=0,则必定有B=0(此时,适用盛金公式1解题)。
盛金定理7:当Δ=0时,若B≠0,盛金公式3一定不存在A≤0的值(此时,适用盛金公式3解题)。
盛金定理8:当Δ<0时,盛金公式4一定不存在A≤0的值。(此时,适用盛金公式4解题)。
盛金定理9:当Δ<0时,盛金公式4一定不存在T≤-1或T≥1的值,即T出现的值必定是-1<T<1。
显然,当A≤0时,都有相应的盛金公式解题。
注意:盛金定理逆之不一定成立。如:当Δ>0时,不一定有A<0。
盛金定理表明:盛金公式始终保持有意义。任意实系数的一元三次方程都可以运用盛金公式直观求解。
#include <cstdio> #include <iostream> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; #define ll long long const int inf = 0x3f3f3f3f; const int mod = 1e9+7; int main() { double a,b,c,d; double as,bs,t,si; double x1,x2,x3; cin>>a>>b>>c>>d; as=b*b-3*a*c; bs=b*c-9*a*d; t=(2*as*b-3*a*bs)/(2*sqrt(as*as*as)); si=acos(t); x1=(-b-2*sqrt(as)*cos(si/3))/(3*a); x2=(-b+sqrt(as)*(cos(si/3)+sqrt(3)*sin(si/3)))/(3*a); x3=(-b+sqrt(as)*(cos(si/3)-sqrt(3)*sin(si/3)))/(3*a); cout<<fixed<<setprecision(2)<<x1<<" "; cout<<fixed<<setprecision(2)<<x3<<" "; cout<<fixed<<setprecision(2)<<x2<<endl; return 0; }