[AcWing]883. 高斯消元解线性方程组(C++实现)高斯消元解线性方程组模板题
1. 题目
2. 读题(需要重点注意的东西)
思路:
即模拟线性代数的求通解过程
注:高斯消元中的① ② ③ ④ 对应代码中注释的① ② ③ ④
3. 解法
---------------------------------------------------解法---------------------------------------------------
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 110;
/* C++浮点数存在误差,不能直接判断0,要判断是否小于一个很小的数,
如果小于这个很小的数,就认为是0,如小于1e-6*/
const double eps = 1e-6;
int n;
double a[N][N];
int gauss()
{
int c, r;// c列,r行
for (c = 0, r = 0; c < n; c ++ )
{
int t = r;
// ① 找到当前这一列中绝对值最大的一行
for (int i =</