zcmimi's blog
查看原题

点击跳转

#include<bits/stdc++.h>
#define FOR(i,x,y) for(int i=x;i<=y;++i)
int n;
double a[111][111];
int main(){
    scanf("%d",&n);
    FOR(i,1,n)FOR(j,1,n+1)scanf("%lf",&a[i][j]);
    FOR(i,1,n){
        int mx=i;
        FOR(j,i+1,n)if(abs(a[j][i])>abs(a[mx][i]))mx=j;
        if(!a[mx][i])return printf("No Solution\n"),0;
        std::swap(a[i],a[mx]);
        FOR(j,1,n)if(j!=i){
            double t=a[j][i]/a[i][i];
            FOR(k,i+1,n+1)
                a[j][k]-=a[i][k]*t;
        }
    }
    FOR(i,1,n)printf("%.2f\n",a[i][n+1]/a[i][i]);
}
LG 3389 【模板】高斯消元法
comment评论
Search
search