P4035 [JSOI2008] Spherical space generator title Main topic
The n+1 points on the n-dimensional space are given, and the stores are on a round surface, seeking the coordinates of the circle center.
Defined:
Sphere: A point of equal distance to any point on the sphere.
Distance formula between two points
\[A (x_1,x_2,x_3,x_4,\cdots x_n) \]
\[B (y_1,y_2,y_3,y_4,\cdots y_n) \]
\[Distance:\sqrt[2]{\sum_{i=1}^{n} (x_i-y_i) ^2} \]
The title should look like a solution to the equation.
We can use the Gauss elimination method .
But here's the problem. This is a two-time multivariate equation set. And our Gauss can only be solved once. And the premise of Gauss is that there are n unknowns, we must have n equations. ( of course, some are not rigorous )
We need to consider moving items and setting an unknown .
One of the original equations: we set a number first,
R。 Indicates that the radius a is a point based on the standard equation of the circle, and R is the center
\[a (x_1,x_2,x_3,x_4,\cdots x_n) \]
\[r (y_1,y_2,y_3,y_4,\cdots y_n) \]
\[\sum_{i=1}^{n} (x_i-y_i) ^2=r^2\]
\[\sum_{i=1}^{n}x_i^2-\sum_{i=1}^{n}2x_iy_i+\sum_{i=1}^{n}y_i^2=r^2\]
Please note that the coordinates of a are known quantities. The coordinates of R and R are not
Then we move the item
\[-\sum_{i=1}^{n}2x_iy_i+ (\sum_{i=1}^{n}y_i^2-r^2) =-\sum_{i=1}^{n}x_i^2\]
The most winding step is the substitution of the whole in parentheses (or as an unknown)
So there is an unknown n+1. And after we solve the equation, we only need the first n unknowns. The unknowns behind us were solved. But it's no use. Just one of our helper variables
At the same time, this question also tells us some small tricks.
- It is impossible for the author to give more conditions. Some of them are for us to set ourselves up.
- Encountered two-time equations. You can consider splitting parentheses and moving items. And then restore to a power-down purpose
#include <cstdio>#include <algorithm>#include <iostream>#include <cmath>using namespaceStdDoublemap[ the][ the];Doubleans[ the];intNvoidGauss () { for(intI=1; i<=n+1; i++) {intR=i; for(intJ=i+1; j<=n+1; j + +)if(Fabs (Map[r][i]) <fabs (Map[j][i])) r=j;if(r!=i) for(intJ=i;j<=n+2; j + +) Swap (map[i][j],map[r][j]);DoubleDiv=map[i][i]; for(intJ=i;j<=n+2; j + +) Map[i][j]/=div; for(intJ=i+1; j<=n+1; j + +) {Div=map[j][i]; for(intK=i;k<=n+2; k++) map[j][k]-=div*map[i][k]; }} ans[n+1]=map[n+1][n+2]; for(inti=n;i>=1; i--) {Ans[i]=map[i][n+2]; for(intJ=i+1; j<=n+1; j + +) Ans[i]-=map[i][j]*ans[j]; }}intMain () {scanf ("%d", &n); for(intI=1; i<=n+1; i++) {DoubleData for(intj=1; j<=n;j++) {scanf ("%LF", &data); map[i][j]=-2.0*data; Map[i][n+2]-=data*data; } map[i][n+1]=1; } gauss (); printf"%.3LF", ans[1]); for(intI=2; i<=n;i++) printf (" %.3LF", Ans[i]);}
P4035 [JSOI2008] Spherical space generator