当前位置:网站首页>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
}
边栏推荐
- 使用BigDecimal的坑
- Unity uses mesh to realize real-time point cloud (I)
- asp. How to call vb DLL function in net project
- 消费互联网的产业链其实是很短的,它仅仅承接平台上下游的对接和撮合的角色
- 【BW16 应用篇】安信可BW16模组/开发板AT指令实现MQTT通讯
- JS逆向教程第一发
- Colorbar of using vertexehelper to customize controls (II)
- How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
- CDZSC_2022寒假个人训练赛21级(2)
- Esp8266 uses TF card and reads and writes data (based on Arduino)
猜你喜欢

VSCode+mingw64+cmake

Detailed explanation of diffusion model

Flex flexible layout

JS逆向教程第一发

Information Security Experiment 2: using x-scanner scanning tool

How will fashion brands enter the meta universe?

CSDN salary increase technology - learn about the use of several common logic controllers of JMeter

Install pyqt5 and Matplotlib module

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

Strategic cooperation subquery becomes the secret weapon of Octopus web browser
随机推荐
Elaborate on MySQL mvcc multi version control
Information Security Experiment 2: using x-scanner scanning tool
How to solve the problem of golang select mechanism and timeout
请教个问题,我用sql-client起了个同步任务,从MySQL同步到ADB,历史数据有正常同步过去
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
[4G/5G/6G专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力
第一讲:寻找矩阵的极小值
First issue of JS reverse tutorial
**Grafana installation**
Vs2013 generate solutions super slow solutions
IIS faked death this morning, various troubleshooting, has been solved
创建一个长度为6的int型数组,要求数组元素的值都在1-30之间,且是随机赋值。同时,要求元素的值各不相同。
用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景
PLC信号处理系列之开关量信号防抖FB
JS inheritance prototype
Selenium+bs4 parsing +mysql capturing BiliBili Tarot data
Sqlplus garbled code problem, find the solution
ViewPager2和VIewPager的區別以及ViewPager2實現輪播圖
第一讲:鸡蛋的硬度