bzoj1013-[JSOI2008]球形空间产生器

高斯小圆。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
#define rep(i,l,r) for(register int i=(l);i<=(r);++i)
#define repdo(i,l,r) for(register int i=(l);i>=(r);--i)
#define il inline
typedef double db;
typedef long long ll;

//---------------------------------------
const int nsz=25;
const db eps=1e-8;
int n;
db line[nsz][nsz],a[nsz][nsz],ans[nsz];
int gauss(){
	int p0;
	db tmp;
	rep(i,1,n){
		p0=i;
		rep(j,i+1,n)if(fabs(a[p0][i])<fabs(a[j][i]))p0=j;
		if(p0!=i)rep(j,1,n+1)swap(a[i][j],a[p0][j]);
		if(fabs(a[i][i])<eps)return 0;
		rep(j,1,n){
			if(j==i)continue;
			tmp=a[j][i]/a[i][i];
			rep(k,i+1,n+1)a[j][k]-=a[i][k]*tmp;
		}
	}
	rep(i,1,n)a[i][n+1]/=a[i][i],ans[i]=a[i][n+1];
	return 1;
}
il db p2(db v){return v*v;}
void sol(){
	rep(i,2,n+1){
		rep(j,1,n){
			a[i-1][j]+=2*(line[i][j]-line[1][j]);
			a[i-1][n+1]+=p2(line[i][j])-p2(line[1][j]);
		}
	}
	gauss();
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n;
	rep(i,1,n+1)rep(j,1,n)cin>>line[i][j];
	sol();
	rep(i,1,n)printf("%.3lf ",ans[i]);
	return 0;
}
posted @ 2018-10-22 12:55  Ubospica  阅读(101)  评论(0编辑  收藏  举报