http://www.lydsy.com/JudgeOnline/problem.php?id=1013
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 ball surface, 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 (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 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 Input 2
0.0 0.0
-1.0 1.0
1.0 0.0Sample Output 0.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 the space point A, B coordinates (a1, a2, ..., an), (B1, B2, ..., bn), the distance of AB is defined as: dist = sqrt ((A1-B1) ^2 + (A2-B2) ^2 + ... + (an-bn) ^2)
Gaussian elimination of the naked problem.
We set the spherical sphere according to the formula (X1,X2,X3......XN) to get:
(a1-x1) ^2 + (a2-x2) ^2 + ... + (AN-XN) ^2= (b1-x1) ^2 + (b2-x2) ^2 + ... + (BN-XN) ^2
Simplification gets:
2 (A1-B1) x1+2 (A2-B2) x2+...+2 (an-bn) xn= (a1^2+a2^2+...+an^2-b1^2-b2^2-...-b3^2)
Can get n formulas, Gaussian elimination can be.
#include <algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<cmath>using namespaceStd;typedefDoubleDL;Const intn= -;intN,M;DL C[n][n],f[n][n],ans[n];inlinevoidGauss () { for(intI=1; i<=n;i++){ intL=i; for(intj=l+1; j<=n;j++) if(Fabs (F[l][i]) <fabs (F[j][i]) l=J; if(l!=i) for(intj=i;j<=m;j++) Swap (f[l][j],f[i][j]); for(intj=i+1; j<=n;j++) {DL temp=f[j][i]/F[i][i]; for(intk=i;k<=m;k++) F[j][k]=f[j][k]-f[i][k]*temp; } } for(inti=n;i>=1; i--) {DL T=F[i][m]; for(intj=n;j>i;j--) T-=ans[j]*F[i][j]; Ans[i]=t/F[i][i]; } return ;}intMain () {scanf ("%d", &n); m=n+1; for(intI=0; i<=n;i++){ for(intj=1; j<=n;j++) {scanf ("%LF",&C[i][j]); } } for(intI=1; i<=n;i++){ intj=i-1;d L d=0; for(intk=1; k<=n;k++) {F[i][k]= (C[i][k]-c[j][k]) *2; D+=c[i][k]*c[i][k]-c[j][k]*C[j][k]; } F[i][m]=D; } Gauss (); for(intI=1; i<=n;i++){ if(i<n) printf ("%.3LF", Ans[i]); Elseprintf"%.3lf\n", Ans[i]); } return 0;}
BZOJ1013:[JSOI2008] Spherical Space generator--the solving