当前位置:网站首页>Gauss elimination
Gauss elimination
2022-07-07 09:47: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 It means that there is an infinite solution ,1 It means that there is a unique solution
// Test Luogu 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 There is no solution ,0 It means that there is an infinite solution ,1 It means that there is a unique solution
// Test Luogu 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; // unsolvable
if (f2) return 0; // Infinite solutions
return 1; // Unique solution
}
边栏推荐
- Software modeling and analysis
- How to use clipboard JS library implements copy and cut function
- Difference between process and thread
- 根据热门面试题分析Android事件分发机制(一)
- 大佬们,有没有遇到过flink cdc读MySQLbinlog丢数据的情况,每次任务重启就有概率丢数
- PostgreSQL创建触发器的时候报错,
- Flex flexible layout
- JS reverse tutorial second issue - Ape anthropology first question
- Scratch crawler mysql, Django, etc
- 在EXCEL写VBA连接ORACLE并查询数据库中的内容
猜你喜欢
JMeter JDBC batch references data as input parameters (the simplest method for the whole website)
First issue of JS reverse tutorial
第一讲:包含min函数的栈
H5网页播放器EasyPlayer.js如何实现直播视频实时录像?
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
Over 100000 words_ Ultra detailed SSM integration practice_ Manually implement permission management
基于智慧城市与储住分离数字家居模式垃圾处理方法
Colorbar of using vertexehelper to customize controls (II)
20排位赛3
Sqlplus garbled code problem, find the solution
随机推荐
牛客网——华为题库(61~70)
2020CCPC威海 J - Steins;Game (sg函数、线性基)
In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
Unity uses mesh to realize real-time point cloud (I)
How to solve the problem of golang select mechanism and timeout
Switching value signal anti shake FB of PLC signal processing series
如何成为一名高级数字 IC 设计工程师(5-2)理论篇:ULP 低功耗设计技术精讲(上)
Gym - 102219J Kitchen Plates(暴力或拓扑序列)
12、 Sort
Selenium+bs4 parsing +mysql capturing BiliBili Tarot data
沙龙预告|GameFi 领域的瓶颈和解决方案
Network request process
Colorbar of using vertexehelper to customize controls (II)
MySQL can connect locally through localhost or 127, but cannot connect through intranet IP (for example, Navicat connection reports an error of 1045 access denied for use...)
CMD startup software passes in parameters with spaces
如何使用clipboard.js库实现复制剪切功能
Scratch crawler mysql, Django, etc
Dynamics 365online applicationuser creation method change
Octopus future star won a reward of 250000 US dollars | Octopus accelerator 2022 summer entrepreneurship camp came to a successful conclusion
**Grafana installation**