# bzoj1013 [JSOI2008]球形空间产生器sphere

$n$维空间的两点间距离公式

$$\sqrt{(a_{1}-a_{2})^{2}+(b_{1}-b_{2})^{2}+……}$$

$$\sqrt{(x_{11}-x_{1})^{2}+(x_{12}-x_{2})^{2}+……+(x_{1n}-x_{n})^{2}}=\sqrt{(x_{i1}-x_{1})^{2}+(x_{i2}-x_{2})^{2}+……+(x_{in}-x_{n})^{2}}$$

$$-2*(x_{i1}-x_{11})x_{1}-2*(x_{i2}-x_{12})x_{2}-……-2*(x_{in}-x_{1n})x_{n}=x_{11}^{2}-x_{i1}^{2}+x_{12}^{2}-x_{i2}^{2}+……+x_{1n}^{2}-x_{in}^{2}$$

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
const int N=20+10;
double a[N][N];
double f[N];
double p;

void Gauss_jordan()
{
for(int i=1;i<=n;i++)
{
int now=i;
for(int j=i+1;j<=n;j++)
if(a[j][i]>a[now][i])
now=j;
for(int j=i;j<=n+1;j++)
swap(a[now][j],a[i][j]);
for(int j=i+1;j<=n+1;j++)
a[i][j]/=a[i][i];
a[i][i]=1;
for(int j=i+1;j<=n;j++)
{
for(int k=i+1;k<=n+1;k++)
a[j][k]-=a[j][i]*a[i][k];
a[j][i]=0;
}
}
for(int i=n;i>=1;i--)
for(int j=i+1;j<=n;j++)
{
a[i][n+1]-=a[i][j]*a[j][n+1];
a[i][j]=0;
}
}
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++)
{
scanf("%lf",&p);
a[i][j]=2.0*(p-f[j]);
a[i][n+1]=a[i][n+1]+p*p-f[j]*f[j];
}
Gauss_jordan();
for(int i=1;i<=n;i++)
printf("%.3lf ",a[i][n+1]);
return 0;
}
View Code

+ 订阅