当前位置:网站首页>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
}
边栏推荐
- Unity shader (learn more about vertex fragment shaders)
- HCIP 第一天 笔记整理
- 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)
- 面试被问到了解哪些开发模型?看这一篇就够了
- NATAPP内网穿透
- CodeForces - 1324D Pair of Topics(二分或双指针)
- La différence entre viewpager 2 et viewpager et la mise en œuvre de la rotation viewpager 2
- 【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
- 用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
- PostgreSQL reports an error when creating a trigger,
猜你喜欢

Vs2013 generate solutions super slow solutions

基础篇:带你从头到尾玩转注解

VSCode+mingw64

JMeter JDBC batch references data as input parameters (the simplest method for the whole website)

Unity3d interface is embedded in WPF interface (mouse and keyboard can respond normally)

Elaborate on MySQL mvcc multi version control

软件建模与分析

使用BigDecimal的坑

H5网页播放器EasyPlayer.js如何实现直播视频实时录像?

Esp8266 uses TF card and reads and writes data (based on Arduino)
随机推荐
章鱼未来之星获得25万美金奖励|章鱼加速器2022夏季创业营圆满落幕
面试被问到了解哪些开发模型?看这一篇就够了
使用BigDecimal的坑
请教个问题,我用sql-client起了个同步任务,从MySQL同步到ADB,历史数据有正常同步过去
網易雲微信小程序
How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
thinkphp3.2信息泄露
ComputeShader
VSCode+mingw64+cmake
其实特简单,教你轻松实现酷炫的数据可视化大屏
Natapp intranet penetration
Oracle installation enhancements error
Information Security Experiment 3: the use of PGP email encryption software
Scratch crawler mysql, Django, etc
如何使用clipboard.js库实现复制剪切功能
用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
scrapy爬虫mysql,Django等
Thinkphp3.2 information disclosure
剑指 Offer II 107. 矩阵中的距离
ViewPager2和VIewPager的區別以及ViewPager2實現輪播圖