显示代码纯文本
#define MAXQ 210UL
#define eps 1e-6
#include <cstdio>
#include <algorithm>
#include <cmath>
struct Point{
double pos[MAXQ];
};
Point point[MAXQ];
int n,m;
double p[MAXQ][MAXQ];
void Add_Fx(int fa,int fb){
++m;
for(int i=1;i<=n;i++){
p[m][i]=(point[fb].pos[i]-point[fa].pos[i])*2.0;
p[m][n+1]+=(point[fb].pos[i]*point[fb].pos[i])-(point[fa].pos[i]*point[fa].pos[i]);
}
return;
}
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",&point[i].pos[j]);
}
}
for(int i=1;i<=n;i++){
Add_Fx(i,i+1);
}
//Gauss
for(int i=1;i<=n;i++){
int pos=-1;
for(int j=i;j<=m;j++){
if(fabs(p[j][i])>eps){
pos=j;break;
}
}
if(pos==-1){
continue;
}
//swap i pos
if(i!=pos){
for(int j=1;j<=n+1;j++){
std::swap(p[i][j],p[pos][j]);
}
}
//xq
double t=p[i][i];
for(int j=1;j<=n+1;j++){
p[i][j]/=t;
}
for(int j=1;j<=m;j++){
if(j!=i&&fabs(p[j][i])>eps){
double r=p[j][i];
for(int k=1;k<=n+1;k++){
p[j][k]*=p[i][i];
p[j][k]-=p[i][k]*r;
}
}
}
}
for(int i=1;i<n;i++){
printf("%.3lf ",p[i][n+1]);
}
printf("%.3lf\n",p[n][n+1]);
return 0;
}