1013 [JSOI2008] spherical space generator sphere Description
There is a spherical space generator capable of producing a hard sphere in n-dimensional space. Now that you're trapped in this n-dimensional sphere, you only know the ball.
The coordinates of the n+1 points on the surface, 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 (1<=n=10). 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 exactly the decimal point.
6 bits, and the 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 accurate to the decimal point
After 3 bits. 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
Tip: Give two definitions: 1, Sphere: points that are equal to any point on the sphere. 2, Distance: Set two n for space on the point A, B
Coordinates for (A1, A2, ..., an), (B1, B2, ..., bn), the distance of AB is defined as: dist = sqrt ((A1-B1) ^2 + (A2-B2) ^2 +
... + (AN-BN) ^2)
Portal
This is the case, originally was in writing another question, the liver has not written out for a long while, checked the next question number found the label is "probability dp+ Gaussian elimination yuan." Because the posture level is not enough, do not know what this is a nasty thing, find a problem to learn. Gaussian elimination is a thing used to solve n-ary linear equations. For linear equations Group $\begin{cases} a_1 x_1 + a_2 x_2 +a_3 x_3 = d_1\\b_1 x_1 + b_2 x_2 +b_3 x_3 = d_2\\c_1 x_1 + c_2 x_2 +c_3 x_3 = d_3 \end{cases}$ we can write an equivalent coefficient matrix $\begin{bmatrix}a_1&a_2&a_3\\b_1&b_2&b_3\\c_1&c_2&c_3\end{ Bmatrix} \times \begin{bmatrix}x_1\\x_2\\x_3\end{bmatrix} = \begin{bmatrix}d_1\\d_2\\d_3\end{bmatrix}$ And what we want to get is such a matrix: $\begin{bmatrix}a_{11}&a_{12}&a_{13}\\0&a_{22}&a_{23}\\0&0&a_{33}\end{ Bmatrix} \times \begin{bmatrix}x_1\\x_2\\x_3\end{bmatrix} = The last line of the \begin{bmatrix}b_1\\b_2\\b_3\end{bmatrix}$ coefficient matrix is $x The solution of _3$, as long as the layer to the ancestors into the elimination of the yuan can be solved all unknown. The specific algorithm flow is this: 1 enumeration of elements in the Matrix $a_{i,i}$, 1.1 from below the absolute value of the largest element $a_{j,i}$; 1.2 The $i$ line is exchanged with section $j$ $[i,n+1]$; 1.3 will be $i$ The row is adjusted to $0$;2 from line $n$ to $1$; for this problem, the distance formula with the square, but the topic gave the $n+1$ clause, with the post-$n$ clause minus the first formula can be eliminated two times.
1#include <cstring>2#include <cstdio>3#include <cmath>4#include <algorithm>5 #defineForu (i,x,y) for (int i=x;i<=y;i++)6 #defineFord (I,X,Y) for (int i=x;i>=y;i--)7 using namespacestd;8 Doublef[ -][ -],x,r[ -];9 intN;Ten One voidGauss () { AForu (I,1, N) { - intt=i; -Foru (j,i+1, N)if(Fabs (F[j][i]) >fabs (F[t][i]) t=J; the if(t!=i) Foru (j,i,n+1) Swap (f[i][j],f[t][j]);//switching improves accuracy -Foru (j,i+1, N) { - Doublex=f[j][i]/F[i][i]; -Foru (k,i,n+1) f[j][k]-=x*F[i][k]; + //F[i][i] The following elements are proportionally reduced to 0 by F[i][i], and the other elements of the peers are proportionally subtracted from the corresponding values of the first row - //that is, the elementary line transformation of matrices + } A } atFord (I,n,1){ - DoubleT= (f[i][n+1]/=f[i][i]); -Foru (J,1, I-1) f[j][n+1]-= (T*f[j][i]);//eliminate Yuan - } - } - in intMain () { -scanf"%d",&n); toForu (I,1, N) scanf ("%LF",&r[i]); +Foru (I,1, N) { -Foru (J,1, N) { thescanf"%LF",&x); *f[i][j]=2* (xr[j]); $f[i][n+1]+=X*X-R[J]*R[J];//elimination of two time itemsPanax Notoginseng } - } the Gauss (); +printf"%.3LF", f[1][n+1]); AForu (I,2, N) printf ("%.3LF", f[i][n+1]); the return 0; +}
bzoj1013 [JSOI2008] Spherical space generator sphere (Gaussian elimination)