显示代码纯文本
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int n,Max_r;
double a[12][12],sum,b[12][12],x[15];
void init(){
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){
sum=0;
for(int j=1;j<=n;++j){
sum+=(a[i+1][j]*a[i+1][j]-a[i][j]*a[i][j]);
b[i][j]=(a[i+1][j]-a[i][j])*2;
}
b[i][n+1]=sum;
}
}
void work(int hang,int lie){
for(int k=1;k<=hang;k++){
Max_r=k;
for(int i=k+1;i<=hang;++i){
if(abs(b[i][k])>abs(b[Max_r][k])) Max_r=i;
}
if(Max_r!=k){
for(int i=k;i<=lie;++i) swap(b[k][i],b[Max_r][i]);
}
for(int j=k+1;j<=n;++j){
double temp=b[j][k]/b[k][k];
for(int l=k;l<=n+1;++l)
b[j][l]-=b[k][l]*temp;
}
}
x[n]=b[n][n+1]/b[n][n];
for(int i=n-1;i>=1;--i){
double temp=b[i][n+1];
for(int j=i+1;j<=n;++j) temp-=b[i][j]*x[j];
x[i]=temp/b[i][i];
}
for(int i=1;i<=n;++i) printf("%.3lf ",x[i]);
}
int main(){
freopen("bzoj_1013.in","r",stdin);
freopen("bzoj_1013.out","w",stdout);
init();
work(n,n+1);
//while(1);
}