其他分享
首页 > 其他分享> > [JSOI2008]球形空间产生器

[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]);
}

标签:15,int,球形,JSOI2008,RE,产生器,text,include,高斯消
来源: https://www.cnblogs.com/leiyuanze/p/15692307.html