显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn=20;
const double eps=1e-8;
double A[maxn][maxn];
void Solve(int n){
for(int i=1;i<=n;i++){
int r=i;
for(int j=i+1;j<=n;j++)
if(fabs(A[j][i])-fabs(A[r][i])>eps)r=j;
if(r!=i){
for(int j=1;j<=n+1;j++)
swap(A[i][j],A[r][j]);
}
double x=A[i][i];
for(int j=i;j<=n+1;j++)A[i][j]/=x;
for(int j=1;j<=n;j++)
if(i!=j){
x=A[j][i];
for(int k=i;k<=n+1;k++)
A[j][k]-=A[i][k]*x;
}
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("bzoj_1013.in","r",stdin);
freopen("bzoj_1013.out","w",stdout);
#endif
int n;
scanf("%d",&n);
for(int i=1;i<=n+1;i++)
for(int j=1;j<=n;j++)
scanf("%lf",&A[i][j]);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
A[i][n+1]-=A[i][j]*A[i][j]-A[i+1][j]*A[i+1][j];
A[i][j]=2*(A[i+1][j]-A[i][j]);
}
}
Solve(n);
for(int i=1;i<=n;i++)
printf("%.3lf ",A[i][n+1]);
printf("\n");
return 0;
}