60分求助

P2455 [SDOI2006] 线性方程组

I_like_play_eggy @ 2024-07-13 13:54:46

#include<bits/stdc++.h>
int n;
double a[106][106];
signed main(){
    scanf("%d",&n);
    for (int i=1;i<=n;i++) for (int j=1;j<=n+1;j++) scanf("%lf",&a[i][j]);
    for (int i=1,max=1;i<=n;max=++i){
        for (int j=i+1;j<=n;j++) if (fabs(a[j][i])>fabs(a[max][i])) max=j;
        if (fabs(a[max][i])<1e-7) for (int j=1;j<=n;j++){
            if (fabs(a[j][n+1]<1e-7)) printf("0\n");
            else printf("1\n");
            return 0;
        }
        if (i!=max) std::swap(a[i],a[max]);
        for (int j=n+1;j>=i;j--) a[i][j]/=a[i][i];
        for (int j=1;j<=n;j++) if (j!=i){
            for (int k=n+1;k>=i;k--) a[j][k]-=a[j][i]*a[i][k];
        }
    }
    for (int i=1;i<=n;i++){
        if (a[i][n+1]==-0.00) printf("x%d=0.00\n",i);
        else printf("x%d=%.2lf\n",i,a[i][n+1]);
    }
    return 0;
}

从模板来的,改了一些,结果一直60pts求解


by Boston_Celtics @ 2024-07-13 13:56:32

我也不会


|