鞍点
#include
#include
using namespace std;
bool findSaddle(const vector>& m) {
int r = m.size();
if (r == 0) return false;
int c = m[0].size();
for (int a = 0; a < r; ++a) {
int b = 0;
for (int d = 1; d < c; ++d) {
if (m[a][d] > m[a][b]) {
b = d;
}
}
bool isSaddle = true;
for (int e = 0; e < r; ++e) {
if (m[e][b] < m[a][b]) {
isSaddle = false;
break;
}
}
if (isSaddle) {
cout << "鞍点坐标为 (" << a << ", " << b << "), 值为: " << m[a][b] << endl;
return true;
}
}
cout << "该矩阵不存在鞍点" << endl;
return false;
}
int main() {
vector> m = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
findSaddle(m);
return 0;
}
#include
using namespace std;
bool findSaddle(const vector>& m) {
int r = m.size();
if (r == 0) return false;
int c = m[0].size();
for (int a = 0; a < r; ++a) {
int b = 0;
for (int d = 1; d < c; ++d) {
if (m[a][d] > m[a][b]) {
b = d;
}
}
bool isSaddle = true;
for (int e = 0; e < r; ++e) {
if (m[e][b] < m[a][b]) {
isSaddle = false;
break;
}
}
if (isSaddle) {
cout << "鞍点坐标为 (" << a << ", " << b << "), 值为: " << m[a][b] << endl;
return true;
}
}
cout << "该矩阵不存在鞍点" << endl;
return false;
}
int main() {
vector> m = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
findSaddle(m);
return 0;
}
全部评论
相关推荐
点赞 评论 收藏
分享
2024-12-20 14:47
海南大学 Java 点赞 评论 收藏
分享