# Bzoj1013: [jsoi2008] spherical space generator sphere (Gaussian elimination)

2021-07-30 04:43:09

## Description

There's a spherical space generator that can be used in n A solid sphere is created in dimensional space . Now? , You're trapped in this n In the sphere , You only know the ball
On the surface n+1 Coordinates of points , You need to determine this as quickly as possible n The coordinates of the center of the sphere , In order to destroy this spherical space generator .

## Input

The first line is an integer n(1<=N=10). Next n+1 That's ok , Each row has n A real number , Representing a point on a sphere n Dimensional coordinates . Every real number is accurate to the decimal point
after 6 position , And its absolute value does not exceed 20000.

## Output

There is only one line , Give the center of the ball in turn n Dimensional coordinates （n A real number ）, Two real numbers are separated by a space . Each real number is accurate to the decimal point
after 3 position . The data is guaranteed to have a solution . Your answer must be as like as two peas .

2
0.0 0.0
-1.0 1.0
1.0 0.0

0.500 1.500

## Code

``` 1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 #include<cmath>
5 #define N  (101)
6 using namespace std;
7
8 double p[N][N],f[N][N],ans[N];
9 int n;
10
11 void Gauss()
12 {
13     for (int i=1; i<=n; ++i)
14     {
15         int num=i;
16         for (int j=i+1; j<=n; ++j)
17             if (fabs(f[j][i])>fabs(f[num][i])) num=j;
18         if (num!=i) swap(f[i],f[num]);
19         for (int j=i+1; j<=n; ++j)
20         {
21             double t=f[j][i]/f[i][i];
22             for (int k=i; k<=n+1; ++k)
23                 f[j][k]-=t*f[i][k];
24         }
25     }
26     for (int i=n; i>=1; --i)
27     {
28         for (int j=i+1; j<=n; ++j)
29             f[i][n+1]-=f[i][j]*ans[j];
30         ans[i]=f[i][n+1]/f[i][i];
31     }
32 }
33
34 int main()
35 {
36     scanf("%d",&n);
37     for (int i=1; i<=n+1; ++i)
38         for (int j=1; j<=n; ++j)
39             scanf("%lf",&p[i][j]);
40     for (int i=1; i<=n; ++i)
41         for (int j=1; j<=n; ++j)
42         {
43             f[i][n+1]+=p[i][j]*p[i][j]-p[i+1][j]*p[i+1][j];
44             f[i][j]=2*(p[i][j]-p[i+1][j]);
45         }
46     Gauss();
47     for (int i=1; i<=n-1; ++i)
48         printf("%.3lf ",ans[i]);
49     printf("%.3lf\n",ans[n]);
50 }```

https://chowdera.com/2021/07/20210728100054999O.html