1.题目链接。题目大意:给出一个n维球面上的n+1个点的坐标,求解这个球心的坐标。
#include<bits/stdc++.h>
#define esp 1e-6
using namespace std;
int n;
#pragma warning(disable:4996)
double f[100], a[100][100];
bool gauss()
{
int now = 1, to; double t;
for (int i = 1; i <= n; i++)
{
for (to = now; to <= n; to++)
if (fabs(a[to][i]) > esp) break;
if (to > n) continue;
if (to != now)
for (int j = 1; j <= n + 1; j++)
swap(a[to][j], a[now][j]);
t = a[now][i];
for (int j = 1; j <= n + 1; j++) a[now][j] /= t;
for (int j = 1; j <= n; j++)
if (j != now)
{
t = a[j][i];
for (int k = 1; k <= n + 1; k++)
a[j][k] -= t * a[now][k];
}
now++;
}
for (int i = now; i <= n; i++)
if (fabs(a[i][n + 1]) > esp) return 0;
return 1;
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)scanf("%lf", &f[i]);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
double tem;
scanf("%lf", &tem);
a[i][j] = 2 * (tem - f[j]);
a[i][n + 1] += tem * tem - f[j] * f[j];
}
}
gauss();
for (int i = 1; i <= n - 1; i++)
{
printf("%.3lf ", a[i][n + 1]);
}
printf("%.3lf\n", a[n][n + 1]);
return 0;
}