【球形空间产生器】
题目
代码
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int N = 12;
double g[N][N];
double ss[N];
int n;
void gauss()
{
int c, r, t;
for(c = 1, r = 1; c <= n; c++)
{
int t = r;
for(int i = r+1; i <= n; i++)
if(fabs(g[i][c]) > fabs(g[t][c])) t = i;
if(fabs(g[t][c]) < eps) continue;
for(int i = c; i <= n+1; i++)
swap(g[t][i], g[r][i]);
for(int i = n+1; i >= c; i--)
g[r][i] /= g[r][c];
for(int i = r+1; i <= n; i++)
for(int j = n+1; j >= c; j--)
g[i][j] -= g[i][c] * g[r][j];
r++;
}
for(int i = n; i >= 2; i--)
for(int j = i-1; j >= 1; j--)
{
g[j][n+1] -= g[j][i] * g[i][n+1];
g[j][i] = 0;
}
}
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n+1; i++)
{
for(int j = 1; j <= n; j++)
{
scanf("%lf", &g[i][j]);
ss[i] += g[i][j] * g[i][j];
}
}
for(int i = 1; i <= n; i++)
{
g[i][n+1] = ss[n+1] - ss[i];
for(int j = 1; j <= n; j++)
{
g[i][j] = 2 * (g[n+1][j] - g[i][j]);
}
}
gauss();
for(int i = 1; i <= n; i++) printf("%.3lf ", g[i][n+1]);
}