Description
There is a spherical space generator capable of producing a hard sphere in n-dimensional space. Now that you are trapped in this n-dimensional sphere, you only know the coordinates of the n+1 points on the sphere, and you need to determine the spherical coordinates of the n-dimensional sphere as quickly as you can to destroy the sphere space generator.
Input
The first line is an integer, N. The next n+1 line, each row has n real numbers, representing the n-dimensional coordinates of a point on the sphere. Each real number is accurate to 6 digits after the decimal point, and its absolute value is no more than 20000.
Output
With only one row, the n-dimensional coordinates (n real numbers) of the globe are given in turn, and two real numbers are separated by a space. Each real number is exactly 3 digits after the decimal point. Data is guaranteed to be solvable. Your answer must be the same as the standard output in order to score.
Sample Input2
0.0 0.0
-1.0 1.0
1.0 0.0Sample Output0.500 1.500HINT
Data size:
For 40% of data, 1<=n<=3
For 100% of data, 1<=n<=10
Tip: Give two definitions:
1, the ball sphere: to the spherical surface any point distance is equal points.
2, Distance: Set two n for Space point A, B coordinates (a1, a2, ..., an), (B1, B2, ..., BN), then AB distance is defined as: dist = sqrt ((A1-B1) ^2 + (A2-B2) ^2 + ... + (an-bn) ^2)
Source
Gaussian elimination of the Naked Question bar. With two adjacent equations one minus, a linear equation comes out.
#include <iostream>#include<cmath>#include<cstring>#include<cstdio>#include<cstdlib>using namespacestd;#defineESP (1E-8)#defineMAXN 15DoubleS[MAXN][MAXN],A[MAXN][MAXN],ANS[MAXN];intN;inlineDoubleQuaDoublex) {returnx*x;} InlinevoidGauss () {inti,j,k; for(i =1; I <= n;++i) { for(j = i;fabs (S[j][i]) <=esp;++j); for(k = i;k <=n+1;++k) Swap (s[j][k],s[i][k]); for(j = i+1; J <= n;++j)if(Fabs (S[j][i]) >ESP) { Doublep = s[i][i]/S[j][i]; for(k = i;k <= n+1;++k) S[j][k]= s[i][k]-s[j][k]*p; } } for(i = n;i;--i) { for(j = i +1; J <= n;++j) S[i][n+1]-= ans[j]*S[i][j]; Ans[i]= s[i][n+1]/S[i][i]; }}intMain () {Freopen ("1013.in","R", stdin); Freopen ("1013.out","W", stdout); scanf ("%d", &n);inti,j; for(i =0; I <= n;++i) for(j =1; J <= N;++j) scanf ("%LF", a[i]+j); for(i =1; I <= n;++i) { for(j =1; J <= n;++j) s[i][j] =2* (a[i][j]-a[i-1][j]); for(j =1; J <= N;++j) s[i][n+1] +=qua (a[i][j]); for(j =1; J <= N;++j) s[i][n+1]-= Qua (a[i-1][j]); } gauss (); for(i =1; i < n;++i) printf ("%.3LF", Ans[i]); printf ("%.3LF", Ans[n]); Fclose (stdin); Fclose (stdout); return 0;}
Bzoj 1013 Spherical Space generator