Sol
设一个dis,就有n+1个方程,消掉dis,就只有n个方程,组成一个方程组,高斯消元就好(建议建立方程时推一下,很简单)
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
int n;
double a[20][20], b[20][20], ans[20], sqr[20];
int main(RG int argc, RG char *argv[]){
scanf("%d", &n);
for(RG int i = 0; i <= n; ++i)
for(RG int j = 1; j <= n; ++j)
scanf("%lf", &b[i][j]), sqr[i] += b[i][j] * b[i][j];
for(RG int i = 1; i <= n; ++i){
for(RG int j = 1; j <= n; ++j)
a[i][j] = 2 * (b[i][j] - b[0][j]);
a[i][n + 1] = sqr[i] - sqr[0];
}
for(RG int i = 1; i < n; ++i)
for(RG int j = i + 1; j <= n; ++j){
RG double div = a[j][i] / a[i][i];
for(RG int k = 1; k <= n + 1; ++k) a[j][k] -= a[i][k] * div;
}
for(RG int i = n; i; --i){
ans[i] = a[i][n + 1] / a[i][i];
for(RG int j = 1; j < i; ++j) a[j][n + 1] -= ans[i] * a[j][i];
}
for(RG int i = 1; i <= n; ++i){
printf("%.3lf", ans[i]);
if(i != n) putchar(' ');
}
return 0;
}