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.
Idea: The equation can be listed, because the distance from each point on the ball to the sphere is equal, so two-phase subtraction can just list n equations, then Gaussian elimination of the element.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <string>6#include <algorithm>7 Doublea[ -][ -],f[ -],t,eps=1e-8;8 intN;9 DoubleSqrDoublex) {Ten returnx*x; One } A voidGauss () { - intnow=1, to;DoubleT; - for(intI=1; i<=n;i++){ the for(to=now;to<=n;to++)if(Fabs (A[to][i]) >eps) Break; - if(to>n)Continue; - if(to!=Now ) - for(intj=1; j<=n+1; j + +) + Std::swap (A[to][j],a[now][j]); -t=A[now][i]; + for(intj=1; j<=n+1; j + +) a[now][j]/=T; A for(intj=1; j<=n;j++) at if(j!=Now ) { -t=A[j][i]; - for(intk=1; k<=n+1; k++) -a[j][k]-=t*A[now][k]; - } -now++; in } - } to intMain () { +scanf"%d",&n); - for(intI=1; i<=n;i++) thescanf"%LF",&f[i]); * for(intI=1; i<=n;i++){ $ for(intj=1; j<=n;j++){Panax Notoginsengscanf"%LF",&t); -a[i][j]=2* (tf[j]); thea[i][n+1]+=SQR (t)-Sqr (F[j]); + } A } the Gauss (); + for(intI=1; i<=n-1; i++) -printf"%.3f", a[i][n+1]); $printf"%.3f\n", a[n][n+1]); $}
BZOJ1013 Spherical Space Generator sphere