Original title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1013
Exercises
The distance from all points to the center of the circle is equal, and we can list n equations, where $i$ is:
$$\sum_{j=1}^{n} (A_{vj}-a_{uj}) *p_j=\sum_{j=1}^{n}-a_{uj}^2+a_{vj}^2$$
where $v=i+1,u=i$
The solution we get is the $p$ matrix.
Code:
/************************************************************** problem:1013 user:harryguo2012 language:c++ result:accepted time:0 Ms memory:1276 kb****************************************************************/#include<iostream>#include<vector>#include<cmath>#include<cstring>#include<iomanip>#defineMax_n 15using namespacestd;Const Doubleeps=1e-8; DoubleA[max_n][max_n];intN;Const intmaxn=Max_n;Const Doubleeps=1e- A;intEquvar;//equ an equation, var variableDoubleX[MAXN];//Solution SetBOOLFREE_X[MAXN];intSgnDoublex) { return(x>eps)-(x<-EPS);}//The Gaussian elimination method is the solution of the equation set (Gauss-jordan elimination). (0 means no solution, 1 means unique solution, greater than 1 means infinite solution, and returns the number of free arguments)intGauss () {equ= N,var= N;//How many equations, how many variables intI, j, K; intMax_r;//The row with the highest absolute value for the current column. intCol//the currently processed column. Doubletemp; intFree_x_num; intFree_index; //converted to a stepped array.Col =0;//the currently processed column.memset (free_x,true,sizeof(free_x)); for(k =0; K < equ && Col <var; k++, col++) {Max_r=K; for(i = k +1; i < equ; i++) { if(SGN (Fabs (A[i][col))-Fabs (A[max_r][col]) >0) Max_r=i; } if(Max_r! = k) {//interchange with section K. for(j = k; J <var+1; J + +) Swap (A[k][j], a[max_r][j]); } if(SGN (a[k][col]) = =0) {//indicates that the COL column K line below is all 0, then the next column of the current row is processed.k--; Continue; } for(i = k +1; i < equ; i++) {//enumerates the rows to be deleted. if(SGN (A[i][col])! =0) {Temp= A[i][col]/A[k][col]; for(j = col; J <var+1; J + +) {A[i][j]= A[i][j]-A[K][J] *temp; } } } } for(i = k; i < equ; i++) { if(SGN (A[i][col])! =0) return 0; } if(K <var) { for(i = k-1; I >=0; i--) {Free_x_num=0; for(j =0; J <var; J + +) { if(SGN (a[i][j])! =0&&Free_x[j]) free_x_num+ +, Free_index =J; } if(Free_x_num >1)Continue; Temp= a[i][var]; for(j =0; J <var; J + +) { if(SGN (a[i][j])! =0&& J! =free_index) Temp-= a[i][j] *X[j]; } X[free_index]= temp/A[i][free_index]; Free_x[free_index]=0; } return var-K; } for(i =var-1; I >=0; i--) {Temp= a[i][var]; for(j = i +1; J <var; J + +) { if(SGN (a[i][j])! =0) Temp-= a[i][j] *X[j]; } X[i]= temp/A[i][i]; } return 1;} DoublePoint[max_n][max_n];intMain () {CIN>>N; for(inti =0; I < n +1; i++) for(intj =0; J < N; J + +) Cin>>Point[i][j]; for(inti =0; I < n; i++) { DoubleTMP =0; for(intj =0; J < N; J + +) {A[i][j]=2* (Point[i +1][J]-Point[i][j]); TMP+ = Point[i +1][J] * point[i +1][J]-POINT[I][J] *Point[i][j]; } A[i][n]=tmp; } gauss (); for(inti =0; I < n; i++) {cout<< Setprecision (3) <<fixed<<X[i]; if(I! = N-1) cout <<" "; } cout<<Endl; return 0;}
Bzoj 1013: [JSOI2008] spherical space generator sphere Gaussian elimination element