记录编号 142031 评测结果 AAAAAAAAAA
题目名称 [JSOI 2008]球形空间产生器sphere 最终得分 100
用户昵称 GravatarAsm.Def 是否通过 通过
代码语言 C++ 运行时间 0.003 s
提交时间 2014-12-05 23:12:27 内存使用 0.31 MiB
显示代码纯文本
//Asm_Def
#include <iostream>
#include <cctype>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
template<typename T>inline void getd(T &x){
    char c = getchar();
    bool minus = 0;
    while(!isdigit(c) && c != '-')c = getchar();
    if(c == '-')minus = 1, c = getchar();
    x = c - '0';
    while(isdigit(c = getchar()))x = x * 10 + c - '0';
    if(minus)x = -x;
}
/*======================================================*/
const double eps = 1e-12;
double *Eq[11], Ans[11];
int N;
inline void init(){
	double a, P[11][12];
	getd(N);int i, j;
	for(j = 0;j < N;++j)scanf("%lf", *P + j);
	for(i = 1;i <= N;++i){
		for(j = 0;j < N;++j)
			scanf("%lf", P[i] + j);
		P[i-1][N] = 0;
		for(j = 0;j < N;++j){
			a = P[i-1][j] + P[i][j];
			P[i-1][j] = P[i][j] - P[i-1][j];
			P[i-1][N] += a * P[i-1][j] / 2.0;
		}
		Eq[i-1] = P[i-1];
	}
}
inline void solve(){
	int i, j, k;
	double frac;
	for(i = 0;i < N;++i){
		for(j = i+1;j < N;++j)
			if(fabs(Eq[i][i]) < fabs(Eq[j][i]))swap(Eq[i], Eq[j]);
		
		if(fabs(Eq[i][i]) < eps){
			cout << "No Answer" << endl;
			exit(1);
		}
		for(j = i+1;j < N;++j){
			if(fabs(frac = Eq[j][i] / Eq[i][i]) < eps)continue;
			Eq[j][i] = 0;
			for(k = i+1;k <= N;++k)
				Eq[j][k] -= frac * Eq[i][k];
		}
	}
	for(i = N-1;i >= 0;--i){
		Ans[i] = Eq[i][N] / Eq[i][i];
		for(j = 0;j < i;++j)
			Eq[j][N] -= Eq[j][i] * Ans[i];
	}
	for(i = 0;i < N;++i)
		printf("%.3lf ", Ans[i]);
}
int main(){
    #if defined DEBUG
    //freopen("test", "r", stdin);
	#else
	freopen("bzoj_1013.in", "r", stdin);
	freopen("bzoj_1013.out", "w", stdout);
    #endif
	init();
	solve();
	
    #if defined DEBUG
    //cout << endl << (double)clock()/CLOCKS_PER_SEC << endl;
    #endif
    return 0;
}