当前位置:网站首页>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
}
边栏推荐
- Nested (multi-level) childrn routes, query parameters, named routes, replace attribute, props configuration of routes, params parameters of routes
- How will fashion brands enter the meta universe?
- Colorbar of using vertexehelper to customize controls (II)
- NATAPP内网穿透
- 小程序实现页面多级来回切换支持滑动和点击操作
- 数据库多表关联查询问题
- CDZSC_2022寒假个人训练赛21级(2)
- 进程和线程的区别
- Niuke - Huawei question bank (61~70)
- IIS redirection redirection appears eurl axd
猜你喜欢
Arthas simple instructions
VSCode+mingw64+cmake
Unity shader (basic concept)
flex弹性布局
Detailed explanation of diffusion model
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)
第一讲:包含min函数的栈
战略合作|SubQuery 成为章鱼网络浏览器的秘密武器
Impression notes finally support the default markdown preview mode
沙龙预告|GameFi 领域的瓶颈和解决方案
随机推荐
scrapy爬虫mysql,Django等
JS逆向教程第一发
根据热门面试题分析Android事件分发机制(一)
创建一个长度为6的int型数组,要求数组元素的值都在1-30之间,且是随机赋值。同时,要求元素的值各不相同。
Strategic cooperation subquery becomes the secret weapon of Octopus web browser
**grafana安装**
# Arthas 简单使用说明
牛客网——华为题库(61~70)
Main (argc, *argv[]) details
nlohmann json
La différence entre viewpager 2 et viewpager et la mise en œuvre de la rotation viewpager 2
在EXCEL写VBA连接ORACLE并查询数据库中的内容
Scratch crawler mysql, Django, etc
JMeter JDBC batch references data as input parameters (the simplest method for the whole website)
CMD startup software passes in parameters with spaces
[4G/5G/6G专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力
基础篇:带你从头到尾玩转注解
第一讲:包含min函数的栈
Dynamics 365online applicationuser creation method change
Oracle安装增强功能出错