This is the portal of the subject.
The main idea of the topic is to compare understood, that is to give you a (n + 1) n-dimensional space on the point, let you ask for this (n + 1) point of the center coordinate.
The first thing I thought of getting this problem was simulated annealing ...
Why? No, why?
But the sense that the correct rate may be problematic, because the problem is not to find the extremum, so only through other methods to determine whether the optimal (such as the standard deviation, but it is really not very reliable)
And think of me before I wrote a simulated annealing topic, adjusted EMMM20 times it, so did not dare to write.
There is a nature in this topic-the nature of the center of the circle
The distance from the center to each point is the same, so we can assume
Suppose the answer is (x1,x2,x3,......, xn), the current point is (A1,a2,a3......,an), and the next is (B1,B2,B3......,BN)
We can list the equations.
(a1-x1) ^ 2 + (a2-x2) ^ 2 + (a3-x3) ^ 2 +......+ (an-xn) ^ 2 = (b1-x1) ^ 2 + (b2-x2) ^ 2 + ... + (AN-XN) ^ 2
Simplification can be
2 (A1-B1) x1 + 2 (a2-b2) x2 + ... +2 (an-bn) xn=a1 ^ 2 + A2 ^ 2 +......+an ^ 2-b1 ^ 2-b2 ^ 2-...-bn ^ 2
We have n + a point altogether
So we can make a list of n equations.
The next step is to use the Gaussian elimination element
Solve all the unknowns, because the data is guaranteed to have the solution, so there is no free element
We can do it boldly.
1#include <cmath>2#include <ctime>3#include <cstdio>4#include <cstring>5#include <iostream>6#include <algorithm>7 #definell Long Long8 #defineDB Double9 #defineFo (i,x,y) for (int i=x; i<=y; i++)Ten #definePR (i,x,y) for (int i=x; i>=y; i--) One #defineCL (a,x) memset (A,x,sizeof (a)) A - using namespacestd; - the intN; -DB mat[ the][ the]; -DB a[ the][ the]; - + intMain () - { +scanf"%d",&N); ACL (Mat,0); atFo (i,1, N +1) - { -Fo (J,1, N) - { -scanf"%LF",&a[i][j]); - if(I! =1) in { -Mat[i-1][j]=2* (A[i][j]-a[i-1][j]); toMat[i-1][n +1]+=A[I][J] * A[i][j]-a[i-1][J] * A[i-1][j]; + } - } the } *Fo (i,1, N) $ {Panax Notoginseng intt=i; -FO (j,i +1, N) the { + if(Fabs (Mat[j][i]) >fabs (Mat[t][i])) A { thet=J; + } - } $ if(T! =i) $ { -Fo (J,1, N +1) - { the swap (mat[i][j],mat[t][j]); - }Wuyi } theFO (j,i +1, N) - { WuDB X=mat[j][i]/Mat[i][i]; -FO (k,i,n +1) About { $MAT[J][K]-=MAT[I][K] *X; - } - } - } APR (I,n,1) + { theFO (j,i +1, N) - { $Mat[i][n +1]-=mat[j][n +1] *Mat[i][j]; the } theMat[i][n +1]/=Mat[i][i]; the } theFo (i,1N1) - { inprintf"%.3f", Mat[i][n +1]); the } theprintf"%.3f\n", Mat[n][n +1]); About return 0; the}
View Code
Bzoj 1013 [JSOI2008] spherical space generator sphere