1013: [JSOI2008] spherical space generator sphere time limit:1 Sec Memory limit:162 MB
submit:2171 solved:1138
[Submit] [Status] 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.0
Sample Output0.500 1.500
HINT
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
(a1-a) ^2+ (b1-b) ^2+...+ (z1-z) ^2= (a2-a) ^2+ (b2-b) ^2+...+ (z2-z) ^2
--》
(A2-A1) *a+2* (B2-B1) *b+...+2* (Z2-Z1) *z=a2^2+b2^2+...+z2^2-a1^2-a2^2-a3^2
Rare water problems, two points to note, the topic " your answer must be the same as the standard output to score" implies that there can be no extra space at the end of the line, to determine the non-0 do not write if (ABS (x) <eps) if (x<eps)
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;#defineMAXN 1000#defineEPS 1e-9#defineABS (x) ((x) >0? ( x):(-(x)))//(a1-a) ^2+ (b1-b) ^2+...+ (z1-z) ^2= (a2-a) ^2+ (b2-b) ^2+...+ (z2-z) ^2//( a2-a1) *a+2* (B2-B1) *b+...+2* (Z2-Z1) *z=a2^2+b2^2+...+z2^2-a1^2-a2^2-a3^2//ACDoubleV[MAXN][MAXN];DoubleMAP[MAXN][MAXN];intN;voidpm () {inti,j; for(i=0; i<n;i++) { for(j=0; j<=n;j++) {printf ("%.4LF", Map[i][j]); } printf ("\ n"); }}DoubleANS[MAXN];intMain () {Freopen ("Input.txt","R", stdin); intI,j,k,x,y,z,a,b,c; scanf ("%d",&N); for(i=0; i<=n;i++) { for(j=0; j<n;j++) {scanf ("%LF",&V[i][j]); } } Doublet=0; for(i=0; i<n;i++) {T=0; for(j=0; j<n;j++) {Map[i][j]=2* (v[i+1][j]-V[i][j]); T+=v[i+1][j]*v[i+1][j]-v[i][j]*V[i][j]; } Map[i][n]=T; }//pm (); for(i=0; i<n;i++) { for(j=i;j<n;j++) { if(ABS (Map[j][i]) >EPS) { Break; } } if(j!=i) { for(k=0; k<=n;k++) Swap (map[i][k],map[j][k]); } for(j=i+1; j<n;j++) {T=map[j][i]/Map[i][i]; for(k=i;k<=n;k++) {Map[j][k]-=t*Map[i][k]; } } }//pm (); for(i=n-1; i>=0; i--) {T=Map[i][n]; for(j=i+1; j<n;j++) {T-=map[i][j]*Ans[j]; } Ans[i]=t/Map[i][i]; } for(i=0; i<n-1; i++) {printf ("%.3LF", Ans[i]); } printf ("%.3lf\n", ans[n-1