当前位置:网站首页>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
}
边栏推荐
- Addition, deletion, modification and query of ThinkPHP database
- Vs2013 generate solutions super slow solutions
- # Arthas 简单使用说明
- **grafana安装**
- Loxodonframework quick start
- Unity shader (to achieve a simple material effect with adjustable color attributes only)
- 在EXCEL写VBA连接ORACLE并查询数据库中的内容
- scrapy爬虫mysql,Django等
- Octopus future star won a reward of 250000 US dollars | Octopus accelerator 2022 summer entrepreneurship camp came to a successful conclusion
- 4、 Fundamentals of machine learning
猜你喜欢
Unity3d interface is embedded in WPF interface (mouse and keyboard can respond normally)
js逆向教程第二发-猿人学第一题
Natapp intranet penetration
Information Security Experiment 4: implementation of IP packet monitoring program
Unity shader (basic concept)
[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 uses TF card and reads and writes data (based on Arduino)
Diffusion模型详解
[bw16 application] Anxin can realize mqtt communication with bw16 module / development board at instruction
網易雲微信小程序
随机推荐
flinkcdc采集oracle在snapshot阶段一直失败,这个得怎么调整啊?
Database multi table Association query problem
Basic use of JMeter to proficiency (I) creation and testing of the first task thread from installation
Upload taro pictures to Base64
ViewPager2和VIewPager的区别以及ViewPager2实现轮播图
thinkphp数据库的增删改查
Unity uses mesh to realize real-time point cloud (I)
VSCode+mingw64+cmake
AI从感知走向智能认知
使用BigDecimal的坑
How to become a senior digital IC Design Engineer (1-6) Verilog coding Grammar: Classic Digital IC Design
Difference between process and thread
细说Mysql MVCC多版本控制
How will fashion brands enter the meta universe?
Pick up the premise idea of programming
js逆向教程第二发-猿人学第一题
Detailed explanation of diffusion model
Natapp intranet penetration
根据热门面试题分析Android事件分发机制(二)---事件冲突分析处理
如何成为一名高级数字 IC 设计工程师(1-6)Verilog 编码语法篇:经典数字 IC 设计