显示代码纯文本
#include<cstdio>
#include<bitset>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
double map[12][12];
double cs[12][12];
int flag=0;
int main()
{
freopen("bzoj_1013.in","r",stdin);
freopen("bzoj_1013.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n+1;i++){
for(int j=1;j<=n;j++)
scanf("%lf",&map[i][j]);
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++){
cs[i][j]=2*(map[i][j]-map[i+1][j]);
cs[i][n+1]+=map[i][j]*map[i][j]-map[i+1][j]*map[i+1][j];
}
}
for(int i=1;i<=n;i++){
flag=0;
for(int j=i;j<=n;j++){
if(cs[j][i]!=0){
flag=j;
break;
}
}
swap(cs[i],cs[flag]);
double tt=cs[i][i];
for(int j=1;j<=n+1;j++)
cs[i][j]/=tt;
for(int j=1;j<=n;j++){
if(i==j) continue;
if(cs[j][i]==0) continue;
tt=cs[j][i];
for(int k=1;k<=n+1;k++){
cs[j][k]-=cs[i][k]*tt;
}
}
}
for(int i=1;i<=n;i++){
printf("%.3lf ",cs[i][n+1]);
}
}