#include <bits/stdc++.h>
using namespace std;
const int N = 250;
int n;
double a[N][N], x[N], p[N][N], q[N][N];
void gauss()
{
for (int i = 1; i <= n; i ++)
{
for (int j = i; j <= n; j ++)
if (a[j][i])
{
for (int k = 1; k <= n + 1; k ++)
swap (a[i][k], a[j][k]);
break;
}
if (a[i][i] == 0)
{
cout << "No Solution\n";
exit(1);
}
for (int j = i + 1; j <= n; j ++)
{
double ratio = a[j][i] / a[i][i];
for (int k = 1; k <= n + 1; k ++)
a[j][k] -= a[i][k] * ratio;
}
}
x[n] = a[n][n + 1] / a[n][n];
for (int i = n; i; i --)
{
for (int j = i + 1; j <= n; j ++)
a[i][n + 1] -= a[i][j] * x[j];
x[i] = a[i][n + 1] / a[i][i];
}
}
signed main()
{
cin >> n;
for (int i = 1; i <= n + 1; i ++)
for (int j = 1; j <= n; j ++)
cin >> p[i][j];
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
{
a[i][j] = 2 * (p[i][j] - p[i + 1][j]);
a[i][n + 1] += p[i][j] * p[i][j] - p[i + 1][j] * p[i + 1][j];
}
gauss();
for (int i = 1; i <= n; i ++)
printf ("%.3lf%c", x[i], " \n"[i == n]);
return 0;
}
标签:std,洛谷,P4035,int,double,void
From: https://www.cnblogs.com/BaiduFirstSearch/p/luogu4035.html