显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdarg>
#include <algorithm>
#include <cmath>
using namespace std;
#define A y
double x[12][12], y[12][12];
void gauss(int n)
{
for(int i = 0; i < n; i++)
{
int r = i;
for(int j = i+1; j < n; j++)
if(fabs(A[j][i]) > fabs(A[r][i]))
r = j;
if(r != i)
for(int j = 0; j <= n; j++)
swap(A[i][j], A[r][j]);
for(int j = n; j >= i; j--)
for(int k = i+1; k < n; k++)
A[k][j] -= A[k][i]/A[i][i]*A[i][j];
}
for(int i = n-1; i >= 0; i--)
{
for(int j = i+1; j < n; j++)
A[i][n] -= A[j][n]*A[i][j];
A[i][n] /= A[i][i];
}
}
int main()
{
freopen("bzoj_1013.in", "r", stdin);
freopen("bzoj_1013.out", "w", stdout);
int n;
scanf("%d", &n);
for(int i = 0; i <= n; i++)
for(int j = 0; j < n; j++)
scanf("%lf", x[i]+j);
for(int i = 0; i < n; i++)for(int j = 0; j < n; j++)
{
y[i][j] = -(x[i][j]-x[i+1][j])*2;
y[i][n] += (x[i+1][j]+x[i][j])*(x[i+1][j]-x[i][j]);
}
gauss(n);
for(int i = 0; i < n; i++)printf("%.3lf ", y[i][n]);
return 0;
}