# 高斯消元总结

\begin{align*} 6x+8y+6z &= 10 \\ 4x+7y+9z &= 10 \\ 4x+6y+7z &= 4 \\ \end{align*}

\begin{bmatrix}
6 & 8 & 6 & 10\\
4 & 7 & 9 & 10\\
4 & 6 & 7 & 4\\
\end{bmatrix}

\begin{bmatrix}
6 & 8 & 6 & 10\\
0 & 2.5 & 7.5 & 5\\
4 & 6 & 7 & 4\\
\end{bmatrix}

\begin{bmatrix}
6 & 8 & 6 & 10\\
0 & 2.5 & 7.5 & 5\\
0 & 1 & 4.5 & -4\\
\end{bmatrix}

\begin{bmatrix}
6 & 8 & 6 & 10\\
0 & 2.5 & 7.5 & 5\\
0 & 0 & 3.75 & -15\\
\end{bmatrix}

$$2.5y=35$$

$$6x=-78$$

\begin{align*} x &= -13 \\ y &= 14 \\ z &= -4 \\ \end{align*}

\begin{bmatrix}
0 & 8 & 6 & 10\\
4 & 7 & 9 & 10\\
4 & 6 & 7 & 4\\
\end{bmatrix}

#include <cstdio>
#include <algorithm>
using namespace std;
double f[92][92],ans[92];
int n;
const double eps=1e-12;
int dcmp(double x)
{
if (x<=eps&&x>=-eps) return 0;
return (x>0)?1:-1;
}
bool gauss()
{
for (int i=1;i<=n;i++)
{
int num=i;
for (int j=i+1;j<=n;j++)
if (dcmp(f[j][i]-f[num][i])>0) num=j;
if (num!=i)
for (int j=1;j<=n+1;j++)
swap(f[i][j],f[num][j]);
for (int j=i+1;j<=n;j++)
if (dcmp(f[j][i]))
{
double t=f[j][i]/f[i][i];
for (int k=1;k<=n+1;k++)
f[j][k]-=t*f[i][k];
}
}
for (int i=n;i>=1;i--)
{
if (dcmp(f[i][i])==0)
return 0;
for (int j=i+1;j<=n;j++)
f[i][n+1]-=f[i][j]*ans[j];
ans[i]=f[i][n+1]/f[i][i];
}
return 1;
}
main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
for (int j=1;j<=n+1;j++)
scanf("%lf",&f[i][j]);
if (gauss())
for (int i=1;i<=n;i++)
printf("%.2lf\n",ans[i]);
else
puts("No Solution");
}