Saliеri @ 2019-07-20 15:34:30
out:-1 ac:0
#include <bits/stdc++.h>
using namespace std;
double A[55][55];
int n;
int 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; i<=n; ++i) {
int max = i;
for(int j=i+1; j<=n; ++j)if(fabs(A[j][i])>fabs(A[max][i]))max = j;
for(int j=1; j<=n+1; ++j)swap(A[i][j],A[max][j]);
if(!A[i][i])continue;
for(int j=1; j<=n; ++j)
if(j!=i)
for(int k=i+1; k<=n+1; ++k)
A[j][k] -= A[i][k]*A[j][i]/A[i][i];
}for(int i=1;i<=n;++i)if(!A[i][i]&&!A[i][n+1]){printf("0");return 0;}
for(int i=1;i<=n;++i)if(!A[i][i]&&A[i][n+1]){printf("-1");return 0;}
for(int i=1;i<=n;++i)printf("x%d=%.2lf\n",i,!A[i][n+1]/A[i][i]?0:A[i][n+1]/A[i][i]);
return 0;
}
求改正
by Saliеri @ 2019-07-20 15:34:56
忽略输出
by cccgift @ 2019-08-07 07:55:24
巧了……