### 1013: [JSOI2008]球形空間產生器sphere

(a11x1)2+(a12x2)2+(a1nxn)2=r2 $(a_{11}-x_1)^2+(a_{12}-x_2)^2+(a_{1n}-x_n)^2=r^2$
(a21x1)2+(a22x2)2+(a2nxn)2=r2 $(a_{21}-x_1)^2+(a_{22}-x_2)^2+(a_{2n}-x_n)^2=r^2$
$……$

#include <algorithm>#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <queue>using namespace std;#define eps 1e-9const int M=30;double f[M],a[M][M];int n;void Gauss(){    for(int i=1;i<=n;i++){        int r=i;        for(int j=i+1;j<=n;j++) if(fabs(a[r][i])<fabs(a[j][i])+eps) r=j;        if(r!=i) for(int j=1;j<=n+1;j++) swap(a[i][j],a[r][j]);//不加這兩行巨快……         for(int j=n+1;j>=i;j--)            for(int k=1;k<=n;k++) if(k!=i)                a[k][j]-=a[k][i]/a[i][i]*a[i][j];    }    for(int i=1;i<=n;i++) f[i]=a[i][n+1]/a[i][i];//最后解一個一元一次方程組 }void work(){    Gauss();    for(int i=1;i<n;i++) printf("%.3lf ",f[i]);    printf("%.3lf",f[n]);//輸出格式………… }void init(){    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 t;scanf("%lf",&t);            a[i][j]=2*(t-f[j]);            a[i][n+1]+=t*t-f[j]*f[j];//常數項         }} int main(){    init();    work();    return 0;}