Time limit:1 Sec Memory limit:162 MB
submit:6890 solved:3627
[Submit] [Status] [Discuss] 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)
using the elementary school theorem, no matter how many dimensions, the sphere to the sphere of any point on the distance is equal, so you can use the distance between two points formula solution: D=sqrt (SQR (x1-x) 2+sqr (y1-y) ...)It is possible to list Cn2 equations, but in fact only n equations are required, here the simplified operationit is necessary to use Gaussian elimination to solve multivariate one-time equation, thanks to the template of Zhejiang University seniors.
1#include <iostream>2#include <cstdio>3#include <cmath>4 using namespacestd;5 6 #defineSQR (x) ((x) * (x))7 #defineEPS 1e-68 Const intmaxn= -;9 DoubleA[MAXN][MAXN],X[MAXN];//The equation to the left of the matrix and the equation to the right of the value, after the solution x saved is the resultTen intEquvar;//number of equations and unknowns One /** Return 0 means no solution, 1 indicates a solution*/ A - intN; - DoubleS[MAXN][MAXN]; the - intGauss () - { - intI,j,k,col,max_r; + for(k=0, col=0;k<equ&&col<var; k++,col++) - { +Max_r=K; A for(i=k+1; i<equ;i++) at if(Fabs (A[i][col]) >fabs (A[max_r][col]) max_r=i; - if(Fabs (A[max_r][col]) <eps)return 0; - if(k!=max_r) - { - for(j=col;j<var; j + +) Swap (a[k][j],a[max_r][j]); - swap (X[k],x[max_r]); in } -X[k]/=A[k][col]; to for(j=col+1;j<var; j + +) a[k][j]/=A[k][col]; +a[k][col]=1; - for(i=0; i<equ;i++) the if(i!=k) * { $x[i]-=x[k]*A[i][k];Panax Notoginseng for(j=col+1;j<var; j + +) a[i][j]-=a[k][j]*A[i][col]; -a[i][col]=0; the } + } A return 1; the } + - intMain () $ { $scanf"%d",&n); -equ=var=N; - for(intI=0; i<=n;i++) the for(intj=0; j<n;j++) -scanf"%LF",&s[i][j]);Wuyi for(intI=0; i<n;i++) the { - for(intj=0; j<n;j++) Wu { -a[i][j]=2* (s[i][j]-s[i+1][j]); AboutX[I]+=SQR (S[i][j])-SQR (s[i+1][j]); $ } - } - Gauss (); - for(intI=0; i<n;i++) printf ("%.3LF", X[i]); A return 0; +}
1013: [JSOI2008] spherical space generator sphere