BZOJ1013 [JSOI2008]球形空间产生器sphere 【高斯消元】

tonyfang posted @ 2015年8月30日 17:48 in BZOJ with tags c++ OI , 520 阅读

刚刚看了高斯消元,感觉主观上可以理解。= =

于是就来码了码这题,高斯消元是$O(n^3)$的,毫无压力~

于是这题需要进行一些转化

设球心$(x_1,x_2,x_3,...,x_n)$,题目给出了$n+1$个球面上的点的坐标,我们设为

$a_{1_{1}},a_{1_{2}},a_{1_{3}},...,a_{1_{n}}$

$a_{2_{1}},a_{2_{2}},a_{2_{3}},...,a_{2_{n}}$

$...$

$a_{n+1_{1}},a_{n+1_{2}},a_{n+1_{3}},...,a_{n+1_{n}}$

于是列出$n+1$个方程,设半径(雾?)为dist

$\sqrt{(a_{i_{1}}-x_1)^2+(a_{i_{2}}-x_2)^2+...+(a_{i_{n}}-x_n)^2}=dist,(1 \leq i \leq n+1)$

然后$i$与$i+1$组合一下,相减就变成高斯消元的形式了。

代码~

 

# include <stdio.h>
# include <algorithm>
# include <math.h>
using namespace std;
int n;
double p[13],pp[13],a[13][13],b[13];
inline void gauss() {
	for (int i=1;i<=n;++i) {
		int k=0;
		for (int j=i;j<=n;++j)
			if(fabs(a[j][i])>fabs(a[k][i])) k=j;
		for (int j=1;j<=n+1;++j) swap(a[i][j],a[k][j]);
		for (int j=i+1;j<=n;++j) {
			double temp=-a[j][i]/a[i][i];
			for (int k=i;k<=n+1;++k) a[j][k]+=a[i][k]*temp; 
		}
	}
	for (int i=n;i>=1;--i) {
		for (int j=n;j>i;--j) a[i][n+1]-=a[i][j]*b[j];
		b[i]=a[i][n+1]/a[i][i];
	}
}
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%lf",&p[i]);
	for (int i=1;i<=n;++i) {
		for (int j=1;j<=n;++j) {
			scanf("%lf",&pp[j]);
			a[i][j]=p[j]-pp[j];
			a[i][n+1]+=p[j]*p[j]-pp[j]*pp[j];
		}
		a[i][n+1]/=2;
	}
	gauss();
	for (int i=1;i<=n-1;++i) printf("%.3lf ",b[i]);
	printf("%.3lf\n",b[n]);
} 
navodayaresult2020-5 说:
2023年4月25日 21:33

JNVST Navodaya Result 2023 Class 5th Class 6th 9th 11th Latest Option List, Marks JNVST Navodaya Result 2023 5th Class 6th, 9th, 11th Class navodayaresult2020-5th.in, Jawahar Navodaya Vidyalaya Selection Examination JNVST Navodaya Officers Announced 5th Class 6th, 9th and 11th Class Admissions. The 2023 Result From the Official Webpage Where Understudies can Download Navodaya Vidyalaya. Furthermore, The JNVST Navodaya Choice Rundown we Have Recorded is 2023.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter