Article From:https://www.cnblogs.com/cn-suqingnian/p/9248778.html

Look at the school sister’s code $… A similar $qwq$that feels that his own code wind is metaphysical.

The center coordinates are $O (x_{1}, x_{2},… X_{3}) $

Then, according to the definition of $n$, the distance between the points on the ball and the center is equal.

$n$The formula of distance between two points in a dimensional space

$$\sqrt{(a_{1}-a_{2})^{2}+(b_{1}-b_{2})^{2}+……}$$

So, according to $|OX_{1}|=|OX_{2}|$, $|OX_{1}|=|OX_{3}|$,… $|OX_{1}|=|OX_{n+1}|$

A total of $n$equations.

List the $i$equation in it:

Set up $X_{i} \ (X_{i1}, X_{i2},… X_{in}) $

$$\sqrt{(x_{11}-x_{1})^{2}+(x_{12}-x_{2})^{2}+……+(x_{1n}-x_{n})^{2}}=\sqrt{(x_{i1}-x_{1})^{2}+(x_{i2}-x_{2})^{2}+……+(x_{in}-x_{n})^{2}}$$

The square is square at the same time, then the square is taken apart, and then the $x_{j}^{2}$on the left and the $x_{j}^{2}$on the right are eliminated.

Then it will be found that this becomes an equation once.

The I equation is:

$$-2*(x_{i1}-x_{11})x_{1}-2*(x_{i2}-x_{12})x_{2}-……-2*(x_{in}-x_{1n})x_{n}=x_{11}^{2}-x_{i1}^{2}+x_{12}^{2}-x_{i2}^{2}+……+x_{1n}^{2}-x_{in}^{2}$$

So, $Gauss\_ \ elimination$.

Just fine.

The code is enlisted:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
const int N=20+10;
double a[N][N];
double f[N];
double p;

void Gauss_jordan()
{
    for(int i=1;i<=n;i++)
    {
        int now=i;
        for(int j=i+1;j<=n;j++)
            if(a[j][i]>a[now][i])
                now=j;
        for(int j=i;j<=n+1;j++)
            swap(a[now][j],a[i][j]);
        for(int j=i+1;j<=n+1;j++)
            a[i][j]/=a[i][i];
        a[i][i]=1;
        for(int j=i+1;j<=n;j++)
        {
            for(int k=i+1;k<=n+1;k++)
                a[j][k]-=a[j][i]*a[i][k];
            a[j][i]=0;
        }
    }
    for(int i=n;i>=1;i--)
        for(int j=i+1;j<=n;j++)
        {
            a[i][n+1]-=a[i][j]*a[j][n+1];
            a[i][j]=0;
        }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
      scanf("%lf",&f[i]);
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)
      {
        scanf("%lf",&p);
        a[i][j]=2.0*(p-f[j]);
        a[i][n+1]=a[i][n+1]+p*p-f[j]*f[j];
      }
    Gauss_jordan();
    for(int i=1;i<=n;i++)
      printf("%.3lf ",a[i][n+1]);
    return 0; 
}

View Code

 

Leave a Reply

Your email address will not be published. Required fields are marked *