当前位置:网站首页>高斯消元
高斯消元
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; //唯一解
}
边栏推荐
- JS judge whether checkbox is selected in the project
- 细说Mysql MVCC多版本控制
- js逆向教程第二发-猿人学第一题
- 小程序弹出半角遮罩层
- Loxodonframework quick start
- 【BW16 应用篇】安信可BW16模组/开发板AT指令实现MQTT通讯
- Strategic cooperation subquery becomes the secret weapon of Octopus web browser
- sql 里面使用中文字符判断有问题,哪位遇到过?比如value&lt;&gt;`无`
- scrapy爬虫mysql,Django等
- Nested (multi-level) childrn routes, query parameters, named routes, replace attribute, props configuration of routes, params parameters of routes
猜你喜欢
12、 Sort
【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
数据建模中利用3σ剔除异常值进行数据清洗
JMeter JDBC batch references data as input parameters (the simplest method for the whole website)
Netease Cloud Wechat applet
AI从感知走向智能认知
Strategic cooperation subquery becomes the secret weapon of Octopus web browser
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景
第一讲:包含min函数的栈
农牧业未来发展蓝图--垂直农业+人造肉
随机推荐
第一讲:寻找矩阵的极小值
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
Difference between process and thread
Thinkphp3.2 information disclosure
How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
js逆向教程第二发-猿人学第一题
Dynamics 365online applicationuser creation method change
网易云微信小程序
VSCode+mingw64+cmake
In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
AI从感知走向智能认知
Detailed explanation of diffusion model
其实特简单,教你轻松实现酷炫的数据可视化大屏
Nested (multi-level) childrn routes, query parameters, named routes, replace attribute, props configuration of routes, params parameters of routes
章鱼未来之星获得25万美金奖励|章鱼加速器2022夏季创业营圆满落幕
如何成为一名高级数字 IC 设计工程师(5-2)理论篇:ULP 低功耗设计技术精讲(上)
剑指 Offer II 107. 矩阵中的距离
Netease cloud wechat applet
scrapy爬虫mysql,Django等
golang select机制和超时问题怎么解决