【题目链接】
https://www.lydsy.com/JudgeOnline/problem.php?id=1013
【算法】
高斯消元
【代码】
#include<bits/stdc++.h> using namespace std; const double eps = 1e-8; int i,j,k,n; double a[100][100],c[100][100]; double b[100]; double rate; int main() { scanf("%d",&n); for (i = 1; i <= n + 1; i++) { for (j = 1; j <= n; j++) { scanf("%lf",&a[i][j]); } } for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { c[i][j] = 2 * (a[i+1][j] - a[i][j]); b[i] += a[i+1][j] * a[i+1][j] - a[i][j] * a[i][j]; } } for (i = 1; i <= n; i++) { for (j = i; j <= n; j++) { if(fabs(c[j][i]) > eps) { for (k = 1; k <= n; k++) swap(c[i][k],c[j][k]); swap(b[i],b[j]); } } for (j = 1; j <= n; j++) { if (i == j) continue; rate = c[j][i] / c[i][i]; for (k = i; k <= n; k++) c[j][k] -= c[i][k] * rate; b[j] -= b[i] * rate; } } for (i = 1; i < n; i++) printf("%.3lf ",b[i]/c[i][i]); printf("%.3lf ",b[n]/c[n][n]); return 0; }