#18684: 心得分享


kenny0000331exiler (許洛瑋)

學校 : 義守大學
編號 : 93124
來源 : [59.127.178.72]
最後登入時間 :
2024-01-18 12:10:29
a410. 解方程 -- TYVJ | From: [180.217.251.42] | 發表日期 : 2019-07-28 17:02

這是一開始用通分方法寫出來的 , 但是會卡在係數乘到最後變成0出現bug //測資出現inf

while(T == true){
double n1 , n2 , k1 , k2;
n1 = a[1]*b[0];
n2 = b[1]*a[0];
k1 = a[2]*b[0];
k2 = b[2]*a[0];

    if(n1 > n2){
    k1 = k1 - k2;
    n1 = n1 - n2;
    y = k1/n1;
    x = (a[2] - (a[1]*y))/a[0];
    cout << "x=" << fixed << setprecision(2) << x << "\n" << "y=" << fixed << setprecision(2) << y << "\n";
    T = false;
    }
     if(n2 > n1){
     k2 = k2 - k1;
     n2 = n2 - n1;
     y = k2/n2;
     x = (a[2] - (a[1]*y))/a[0];
     cout << "x=" << fixed << setprecision(2) << x << "\n" << "y=" << fixed << setprecision(2) << y << "\n";
     T = false;
     }


}

 

最後直接放棄用克拉瑪比較簡單....

while(T == true){
double A = (a[0]*b[1]) - (a[1]*b[0]);
double Ax = (a[2]*b[1]) - (a[1]*b[2]);
double Ay = (a[0]*b[2]) - (a[2]*b[0]);
cout << "x=" << fixed << setprecision(2) << Ax/A << "\n" << "y=" << fixed << setprecision(2) << Ay/A << "\n";
T = false;
}

 
ZeroJudge Forum