当前位置:网站首页>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
}
边栏推荐
- First issue of JS reverse tutorial
- 如何成为一名高级数字 IC 设计工程师(1-6)Verilog 编码语法篇:经典数字 IC 设计
- 根据热门面试题分析Android事件分发机制(二)---事件冲突分析处理
- 印象笔记终于支持默认markdown预览模式
- PLC信号处理系列之开关量信号防抖FB
- 进程间的通信方式
- sql 里面使用中文字符判断有问题,哪位遇到过?比如value&lt;&gt;`无`
- [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
- esp8266使用TF卡并读写数据(基于arduino)
- How to become a senior digital IC Design Engineer (5-2) theory: ULP low power design technology (Part 1)
猜你喜欢

小程序实现页面多级来回切换支持滑动和点击操作

csdn涨薪技术-浅学Jmeter的几个常用的逻辑控制器使用

Lecture 1: stack containing min function

Loxodonframework quick start

Use 3 in data modeling σ Eliminate outliers for data cleaning

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

Unity3d interface is embedded in WPF interface (mouse and keyboard can respond normally)
![[Frida practice]](/img/20/fc68bcf2f55b140d6754af6364896b.png)
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
![[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景](/img/fd/5e8f74da25d9c5f7bd69dd1cfdcd61.png)
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景

JS reverse tutorial second issue - Ape anthropology first question
随机推荐
其实特简单,教你轻松实现酷炫的数据可视化大屏
AI从感知走向智能认知
Detailed explanation of diffusion model
大佬们,有没有遇到过flink cdc读MySQLbinlog丢数据的情况,每次任务重启就有概率丢数
章鱼未来之星获得25万美金奖励|章鱼加速器2022夏季创业营圆满落幕
JS reverse tutorial second issue - Ape anthropology first question
How to use clipboard JS library implements copy and cut function
战略合作|SubQuery 成为章鱼网络浏览器的秘密武器
csdn涨薪技术-浅学Jmeter的几个常用的逻辑控制器使用
进程和线程的区别
shake数据库中怎么使用Mongo-shake实现MongoDB的双向同步啊?
有没有大佬帮忙看看这个报错,有啥排查思路,oracle cdc 2.2.1 flink 1.14.4
thinkphp数据库的增删改查
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景
Octopus future star won a reward of 250000 US dollars | Octopus accelerator 2022 summer entrepreneurship camp came to a successful conclusion
Vs2013 generate solutions super slow solutions
# Arthas 简单使用说明
First issue of JS reverse tutorial
In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
ViewPager2和VIewPager的区别以及ViewPager2实现轮播图