当前位置:网站首页>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
}
边栏推荐
- Oracle installation enhancements error
- 12、 Sort
- 数据建模中利用3σ剔除异常值进行数据清洗
- CentOS installs JDK1.8 and mysql5 and 8 (the same command 58 in the second installation mode is common, opening access rights and changing passwords)
- Netease Cloud Wechat applet
- Unity3d interface is embedded in WPF interface (mouse and keyboard can respond normally)
- C# Socke 服务器,客户端,UDP
- IIS faked death this morning, various troubleshooting, has been solved
- 網易雲微信小程序
- 有没有大佬帮忙看看这个报错,有啥排查思路,oracle cdc 2.2.1 flink 1.14.4
猜你喜欢
【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景
Information Security Experiment 1: implementation of DES encryption algorithm
Unity shader (to achieve a simple material effect with adjustable color attributes only)
印象笔记终于支持默认markdown预览模式
Unity shader (basic concept)
Network request process
[4g/5g/6g topic foundation -147]: Interpretation of the white paper on 6G's overall vision and potential key technologies -2-6g's macro driving force for development
Information Security Experiment 3: the use of PGP email encryption software
First issue of JS reverse tutorial
随机推荐
小程序滑动、点击切换简洁UI
软件建模与分析
Information Security Experiment 2: using x-scanner scanning tool
H5 web player easyplayer How does JS realize live video real-time recording?
# Arthas 简单使用说明
Elaborate on MySQL mvcc multi version control
Information Security Experiment 1: implementation of DES encryption algorithm
细说Mysql MVCC多版本控制
JS judge whether checkbox is selected in the project
JMeter JDBC batch references data as input parameters (the simplest method for the whole website)
golang select机制和超时问题怎么解决
網易雲微信小程序
Niuke - Huawei question bank (61~70)
根据热门面试题分析Android事件分发机制(二)---事件冲突分析处理
小程序实现页面多级来回切换支持滑动和点击操作
【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
Detailed explanation of diffusion model
NETCORE 3.1 solves cross domain problems
Create an int type array with a length of 6. The values of the array elements are required to be between 1-30 and are assigned randomly. At the same time, the values of the required elements are diffe
PLC信号处理系列之开关量信号防抖FB