当前位置:网站首页>高斯消元
高斯消元
2022-07-07 07:09:00 【moyangxian】
bool dcmp(int x, int y, int k) {
if (fabs(a[x][k]) > fabs(a[y][k]))
return true;
else if (fabs(a[x][k]) < fabs(a[y][k]))
return false;
else {
for (int i = k + 1; i <= n; i++)
if (fabs(a[x][i]) < fabs(a[y][i])) return true;
return false;
}
}
//0表示有无穷解,1表示有唯一解
//测试洛谷P3389
int Gauss() {
for (int r = 1, c = 1; c <= n; c++, r++) {
int t = r;
for (int i = r + 1; i <= n; i++)
if (fabs(a[i][c]) > fabs(a[t][c]))
t = i;
if (sgn(a[t][c]) == 0) return 0;
if (t != r)for (int i = c; i <= n + 1; i++)swap(a[t][i], a[r][i]);
for (int i = n + 1; i >= c; i--)a[r][i] /= a[r][c];
for (int i = 1; i <= n; i++)
if (i != r) {
for (int j = c + 1; j <= n + 1; j++)
a[i][j] -= a[r][j] * a[i][c];
a[i][c] = 0;
}
}
return 1;
}
//-1表示无解,0表示有无穷解,1表示有唯一解
//测试洛谷P2455
int Gauss() {
for (int r = 1, c = 1; c <= n; c++, r++) {
int t = r;
for (int i = r + 1; i <= n; i++)
if (dcmp(i, t, c)) t = i;
if (t != r) for (int i = c; i <= n + 1; i++) swap(a[t][i], a[r][i]);
if (sgn(a[r][c]) == 0) continue;
for (int i = n + 1; i >= c; i--) a[r][i] /= a[r][c];
a[r][c] = 1;
for (int i = 1; i <= n; i++) {
if (i == r) continue;
for (int j = c + 1; j <= n + 1; j++)
a[i][j] -= a[r][j] * a[i][c];
a[i][c] = 0;
}
}
bool f1 = 0, f2 = 0;
for (int i = 1; i <= n; i++) {
if (sgn(a[i][i]) == 0 && sgn(a[i][n + 1]) != 0) f1 = 1;
if (sgn(a[i][i]) == 0 && sgn(a[i][n + 1]) == 0) f2 = 1;
}
if (f1) return -1; //无解
if (f2) return 0; //无穷多解
return 1; //唯一解
}
边栏推荐
- JS reverse tutorial second issue - Ape anthropology first question
- 根据热门面试题分析Android事件分发机制(一)
- 战略合作|SubQuery 成为章鱼网络浏览器的秘密武器
- [4g/5g/6g topic foundation-146]: Interpretation of white paper on 6G overall vision and potential key technologies-1-overall vision
- In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
- 第一讲:鸡蛋的硬度
- [bw16 application] Anxin can realize mqtt communication with bw16 module / development board at instruction
- Dynamics 365Online ApplicationUser创建方式变更
- IIS faked death this morning, various troubleshooting, has been solved
- 基础篇:带你从头到尾玩转注解
猜你喜欢

Huawei HCIP - datacom - Core 03 jours

第一讲:寻找矩阵的极小值

How to use clipboard JS library implements copy and cut function

Where is the answer? action config/Interceptor/class/servlet

Oracle安装增强功能出错

数据建模中利用3σ剔除异常值进行数据清洗

JS逆向教程第一发
![[cloud native] Devops (I): introduction to Devops and use of code tool](/img/e0/6152b3248ce19d0dbba3ac4845eb65.png)
[cloud native] Devops (I): introduction to Devops and use of code tool

VSCode+mingw64

JMeter JDBC batch references data as input parameters (the simplest method for the whole website)
随机推荐
How to become a senior digital IC Design Engineer (5-2) theory: ULP low power design technology (Part 1)
Unity shader (to achieve a simple material effect with adjustable color attributes only)
scrapy爬虫mysql,Django等
【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
NETCORE 3.1 solves cross domain problems
数据库多表关联查询问题
STM32 and motor development (from stand-alone version to Networking)
基于智慧城市与储住分离数字家居模式垃圾处理方法
细说Mysql MVCC多版本控制
农牧业未来发展蓝图--垂直农业+人造肉
AI从感知走向智能认知
如何使用clipboard.js库实现复制剪切功能
Integer or int? How to select data types for entity classes in ORM
信息安全实验四:Ip包监视程序实现
The difference between viewpager2 and viewpager and the implementation of viewpager2 in the rotation chart
其实特简单,教你轻松实现酷炫的数据可视化大屏
Dynamics 365Online ApplicationUser创建方式变更
asp. How to call vb DLL function in net project
【无标题】
sqlplus乱码问题,求解答