P4035 [JSOI2008] Spherical space generator

P4035 [JSOI2008] Spherical space generator

topic

Topic

Given n+1 points in n-dimensional space, and these stores are all on the surface of a circle, find the coordinates of the center of the circle.

definition:

  1. Center of Sphere: A point that is equidistant from any point on the sphere.

  2. formula for distance 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 problem seems to be solving equations.

We can use gauss elimination .

But here comes the problem. This is a quadratic multivariate system of equations. And our gauss can only be solved once. And the premise of gauss is that with n unknowns, we must have n equations. (Of course it's a bit imprecise

We're going to consider shifting and setting up an unknown .

One of the original equations: we first set a number, r . Represents the radius calculated from the standard equation of a circle
A is a point, R is the center of the circle

\[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 here are all known quantities. while the coordinates of r and R are not

After that, I'm moving \ [-\ 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 devious step is coming
We substitute the whole in parentheses (or treat it as an unknown)

In this way, there are n+1 unknowns. And after we solve the equation, we only need the first n unknowns. The unknowns we set later are solved. But to no avail. just us a helper variable

At the same time, this question also tells us some tips.

  1. The questioner cannot give more conditions. Some are for us to set up
  2. encounter quadratic equations. Consider breaking parentheses and shifting items. Then restore to achieve the purpose of reducing power
#include<cstdio> 
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
double map[15][15];
double ans[15];
int n;
void gauss()
{
    for(int i=1;i<=n+1;i++)
    {
        int r=i;
        for(int j=i+1;j<=n+1;j++)
            if(fabs(map[r][i])<fabs(map[j][i]))
                r=j;
        if(r!=i)
            for(int j=i;j<=n+2;j++)
                swap(map[i][j],map[r][j]);
        double div=map[i][i]; 
        for(int j=i;j<=n+2;j++)
            map[i][j]/=div;
        for(int j=i+1;j<=n+1;j++)
        {
            div=map[j][i];
            for(int k=i;k<=n+2;k++)
                map[j][k]-=div*map[i][k];
        }
    }
    ans[n+1]=map[n+1][n+2];
    for(int i=n;i>=1;i--)
    {
        ans[i]=map[i][n+2];
        for(int j=i+1;j<=n+1;j++)
            ans[i]-=map[i][j]*ans[j];
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n+1;i++)
    {
        double data;
        for(int j=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(int i=2;i<=n;i++)
        printf(" %.3lf",ans[i]);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325041568&siteId=291194637