[JSOI2008]球形空间产生器 题解

第一道应用高斯消元的题目。
题目本质上就是对于$n$个给定点$a$和圆心$x$,有如下关系:

让你求$x$.

使用高斯消元解决。
考虑相邻给出的两个点$a_i$和$b_i$,有:

移项+提取公因式:

右边已知(可以当作常数),左边是一个关于$x$的$n$元方程组。
于是就可以愉快套板子了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @Author: Mingyu Li
* @Date: 2019-03-17T11:46:23+08:00
* @Email: class11limingyu@126.com
* @Filename: P4035.cpp
* @Last modified by: Mingyu Li
* @Last modified time: 2019-03-17T14:30:02+08:00
*/

#include <bits/stdc++.h>
#define Go(i , x , y) for(register int i = x; i <= y; i++)
#define God(i , y , x) for(register int i = y; i >= x; i--)
typedef long long LL;
template < typename T > void sc(T& t) {
char c = getchar(); T x = 1; t = 0; while(!isdigit(c)) {if(c == '-') x = -1; c = getchar();}
while(isdigit(c)) t = t * 10 + c - '0' , c = getchar();t *= x;
}
template < typename T , typename... Args > void sc(T& t , Args&... args) {sc(t); sc(args...);}

const int N = 105;
int n;
double g[N][N] , p[N][N];

void Gauss() {
Go(i , 1 , n) {
int now = i;
Go(j , i+1 , n) if(fabs(g[now][i]) < fabs(g[j][i])) now = j;
Go(j , 1 , n+1) std::swap(g[i][j] , g[now][j]);

Go(j , i+1 , n+1) g[i][j] /= g[i][i];
g[i][i] = 1;
Go(j , i+1 , n) {
Go(k , i+1 , n+1) g[j][k] -= g[j][i] * g[i][k];
g[j][i] = 0;
}
}

God(i , n , 1) {
Go(j , i+1 , n)
g[i][n+1] -= g[i][j] * g[j][n+1];
g[i][n+1] /= g[i][i];
g[i][i] = 1;
}
}
int main() {
sc(n);
Go(i , 1 , n+1)
Go(j , 1 , n)
scanf("%lf" , &p[i][j]);

Go(i , 1 , n) {
Go(j , 1 , n) {
double times = 2 * (p[i][j] - p[i+1][j]);
g[i][j] = times;
g[i][n+1] += (p[i][j] * p[i][j] - p[i+1][j] * p[i+1][j]);
}
}

Gauss();

Go(i , 1 , n) std::cout << std::fixed << std::setprecision(3) << g[i][n+1] << " ";
std::cout << "\n";
return 0;
}

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×