题目链接:https://www.luogu.com.cn/problem/P3389
题目大意:略
解题思路:略(因为是模板题)
示例程序:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
const double eps = 1e-7;
int n;
double a[maxn][maxn];bool gauss() {for (int i = 1; i <= n; i++) {int r = i;for (int j = i+1; j <= n; j++)if (abs(a[j][i]) > abs(a[r][i])) r = j;if (abs(a[r][i]) < eps) return false;for (int j = 1; j <= n+1; j++)swap(a[r][j], a[i][j]);for (int j = n+1; j >= i; j--)a[i][j] /= a[i][i];assert(abs(a[i][i] - 1) < eps);for (int j = 1; j <= n; j++) {if (j == i || abs(a[j][i]) < eps) continue;double tmp = a[j][i];for (int k = i; k <= n+1; k++)a[j][k] -= tmp * a[i][k];}}return true;
}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]);if (!gauss()) puts("No Solution");else {for (int i = 1; i <= n; i++)printf("%.2lf\n", a[i][n+1]);}return 0;
}