[JSOI2008]球形空间产生器

\(\text{Code}\)

经过简单的转换后高斯消元即可
好久没打过高斯消元了,最近的还是 \(\text{two years ago......}\)

#include <cstdio>
#include <iostream>
#define RE register
using namespace std;

int n;
double a[15][15], b[15][15];

int main()
{
	scanf("%d", &n);
	for(RE int i = 1; i <= n + 1; i++)
	{
		for(RE int j = 1; j <= n; j++) scanf("%lf", &b[i][j]);
		if (i > 1) for(RE int j = 1; j <= n; j++)
			a[i - 1][n + 1] += -1.0 * (b[i - 1][j] + b[i][j]) * (b[i - 1][j] - b[i][j]),
			a[i - 1][j] = -2.0 * (b[i - 1][j] - b[i][j]);
	}
	for(RE int i = 1; i <= n; i++)
	{
		for(RE int j = i; j <= n; j++)
		if (a[i][j] != 0)
		{
			for(RE int k = 1; k <= n + 1; k++) swap(a[i][k], a[j][k]);
			break;
		}
		for(RE int j = i + 1; j <= n + 1; j++) a[i][j] /= a[i][i];
		a[i][i] = 1.0;
		for(RE int j = 1; j <= n; j++)
		if (i ^ j)
		{
			double p = a[j][i];
			for(RE int k = 1; k <= n + 1; k++) a[j][k] -= a[i][k] * p;
		}
	}
	for(RE int i = 1; i <= n; i++) printf("%.3lf ", a[i][n + 1]);
}
上一篇:中文句子关系抽取


下一篇:正则表达式