当前位置:网站首页>高斯消元
高斯消元
2022-07-07 07:09: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表示有无穷解,1表示有唯一解
//测试洛谷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表示无解,0表示有无穷解,1表示有唯一解
//测试洛谷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; //无解
if (f2) return 0; //无穷多解
return 1; //唯一解
}
边栏推荐
- Mysql:select ... for update
- 进程和线程的区别
- esp8266使用TF卡并读写数据(基于arduino)
- Create an int type array with a length of 6. The values of the array elements are required to be between 1-30 and are assigned randomly. At the same time, the values of the required elements are diffe
- Thinkphp3.2 information disclosure
- 小程序滑动、点击切换简洁UI
- 战略合作|SubQuery 成为章鱼网络浏览器的秘密武器
- How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
- sql 里面使用中文字符判断有问题,哪位遇到过?比如value&lt;&gt;`无`
- 基础篇:带你从头到尾玩转注解
猜你喜欢

Netease Cloud Wechat applet

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

JMeter JDBC batch references data as input parameters (the simplest method for the whole website)
![[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](/img/21/6a183e4e10daed90c66235bdbdc3bf.png)
[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

Over 100000 words_ Ultra detailed SSM integration practice_ Manually implement permission management

Information Security Experiment 2: using x-scanner scanning tool

# Arthas 简单使用说明

小程序滑动、点击切换简洁UI

细说Mysql MVCC多版本控制

浏览器中如何让视频倍速播放
随机推荐
esp8266使用TF卡并读写数据(基于arduino)
CMD startup software passes in parameters with spaces
4、 Fundamentals of machine learning
H5 web player easyplayer How does JS realize live video real-time recording?
flinkcdc 用sqlclient可以指定mysqlbinlog id执行任务吗
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
JS逆向教程第一发
Thinkphp3.2 information disclosure
创建一个长度为6的int型数组,要求数组元素的值都在1-30之间,且是随机赋值。同时,要求元素的值各不相同。
Detailed explanation of diffusion model
[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
软件建模与分析
Huawei HCIP - datacom - Core 03 jours
[cloud native] Devops (I): introduction to Devops and use of code tool
【无标题】
Unity3d interface is embedded in WPF interface (mouse and keyboard can respond normally)
How to solve the problem of golang select mechanism and timeout
如何使用clipboard.js库实现复制剪切功能
第一讲:寻找矩阵的极小值
IIS redirection redirection appears eurl axd