题意:简化一下 就是解N个 系数矩阵一样 等式右边列矩阵不一样的方程组
题解:系数矩阵一样 为什么我却毫无办法????
其实只要把等式右边的矩阵都排在后面就好了啊
就变成解一个N x 2N的方程组了 ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; int n; double a[205][405]; void gauss() { int now = 1, to; for(int i = 1; i <= n; i++) { to = now; for(int j = now; j <= n; j++) { if(fabs(a[j][i]) > fabs(a[to][i])) to = j; } //if(to > n) continue; if(fabs(a[to][i]) < eps) continue; if(to != now) for(int j = 1; j <= n + n; j++) swap(a[to][j], a[now][j]); double tmp = a[now][i]; //for(int j = 1; j <= n + n; j++) a[now][j] /= tmp; for(int j = 1; j <= n + n; j++) if(j != now) { tmp = a[j][i]; for(int k = 1; k <= n + n; k++) a[j][k] -= tmp * a[now][k]; } now++; } } int main() { //freopen("bujor.in","r",stdin); //freopen("bujor.out","w",stdout); int T; scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) scanf("%lf", &a[i][j]); for(int j = n + 1; j <= n * 2; j++) for(int i = 1; i <= n; i++) { if(i + n == j) a[i][j] = 1; else a[i][j] = 0; } gauss(); for(int i = 1; i <= n; i++) { for(int j = n + 1; j <= 2 * n; j++) { double tmp = a[i][j] / a[i][i]; if(fabs(tmp) < eps) tmp = 0; if(j != 2 * n) printf("%.9lf ", tmp); else printf("%.9lf ", tmp); } } } return 0; }