显示代码纯文本
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define Inf 2e9
const int maxn=1010;
int n;
double pos[maxn][maxn];
void Init();
void Exchange(int x){
for(int i=x+1;i<=n;i++){
if(pos[i][x]!=0){
for(int j=1;j<=n+1;j++)swap(pos[x][j],pos[i][j]);
return;
}
}
}
void Gaosi(){
for(int i=1;i<=n;i++){
if(pos[i][i]==0)Exchange(i);
double x=pos[i][i];
for(int j=i;j<=n+1;j++)pos[i][j]/=x;
for(int j=i+1;j<=n;j++){
x=pos[j][i];
for(int k=i;k<=n+1;k++)pos[j][k]-=x*pos[i][k];
}
}
pos[n][n]=pos[n][n+1]/pos[n][n];
for(int i=n-1;i>=1;i--){
double x=0;
for(int j=i+1;j<=n;j++)x+=pos[i][j]*pos[j][j];
pos[i][i]=(pos[i][n+1]-x)/pos[i][i];
}
for(int i=1;i<=n;i++)printf("%.3lf ",pos[i][i]);
}
int main(){
freopen("bzoj_1013.in","r",stdin);freopen("bzoj_1013.out","w",stdout);
Init();
getchar();getchar();
return 0;
}
void Init(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lf",&pos[0][i]);
pos[0][n+1]-=pos[0][i]*pos[0][i];
pos[0][i]*=-2;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%lf",&pos[i][j]);
pos[i][n+1]-=pos[i][j]*pos[i][j];
pos[i][j]*=-2;
pos[i][j]-=pos[0][j];
}
pos[i][n+1]-=pos[0][n+1];
}
Gaosi();
}
/*
2
4 3
1 0
3 0
*/
/*
2
0.0 0.0
-1.0 1.0
1.0 0.0
*/