Description
There is a spherical space generator capable of generating a hard sphere in n-dimensional space. Now, you are trapped in this n-dimensional sphere, you only know
the coordinates of n+1 points on the sphere, you need to determine the center coordinates of this n-dimensional sphere as quickly as possible in order to destroy this spherical space generator.
Input
The first line is an integer n (1<=N=10). The next n+1 lines, each with n real numbers, represent the n-dimensional coordinates of a point on the sphere. Each real number is accurate to
6 decimal places, and its absolute value does not exceed 20000.
Output
There is one and only one line, which gives the n-dimensional coordinates of the center of the sphere (n real numbers) in turn, and the two real numbers are separated by a space. Each real number is accurate to
3 decimal places. The data is guaranteed to be solvable. Your answer must be exactly the same as the standard output to be awarded a point.
Sample Input
0.0 0.0
-1.0 1.0
1.0 0.0
Sample Output
HINT
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cmath> 5 #define N (101) 6 using namespace std; 7 8 double p[N][N],f[N][N],ans[N]; 9 int n; 10 11 void Gauss() 12 { 13 for (int i=1; i<=n; ++i) 14 { 15 int num=i; 16 for (int j=i+1; j<=n; ++j) if (fabs(f[j][i])>fabs(f[num][i])) num=j; 17 if (num!=i) for (int j=1; j<=n+1; ++j) swap(f[i][j],f[num][j]); 18 19 for (int j=i+1; j<=n+1; ++j) 20 { 21 double t=f[j][i]/f[i][i]; 22 for (int k=i; k<=n+1; ++k) 23 f[j][k]-=t*f[i][k]; 24 } 25 } 26 for (int i=n; i>=1; --i) 27 { 28 for (int j=i+1; j<=n; ++j) f[i][n+1]-=f[i][j]*ans[j]; 29 ans[i]=f[i][n+1]/f[i][i]; 30 } 31 } 32 33 int main() 34 { 35 scanf("%d",&n); 36 for (int i=1; i<=n+1; ++i) 37 for (int j=1; j<=n; ++j) 38 scanf("%lf",&p[i][j]); 39 for (int i=1; i<=n; ++i) 40 for (int j=1; j<=n; ++j) 41 { 42 f[i][n+1]+=p[i][j]*p[i][j]-p[i+1][j]*p[i+1][j]; 43 f[i][j]=2*(p[i][j]-p[i+1][j]); 44 } 45 Gauss(); 46 for (int i=1; i<=n-1; ++i) 47 printf("%.3lf ",ans[i]); 48 printf("%.3lf",ans[n]); 49 }