acwing 3708.求矩阵的鞍点(21_1)
作者:
mahx
,
2024-11-17 23:36:52
,
所有人可见
,
阅读 3
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 12;
int n, m;
int r[N], l[N];
int a[N][N];
int main(){
cin >> n >> m;
for (int i = 0; i < n; i ++ ) {
for (int j = 0; j < m; j ++ ){
cin >> a[i][j];
if(a[i][j] > r[i]) r[i] = a[i][j];//统计每一行的最大值
}
}
for (int j = 0; j < m; j ++ ) l[j] = 10;
for (int j = 0; j < m; j ++ ){
for (int i = 0; i < n; i ++ ){
if(a[i][j] < l[j]) l[j] = a[i][j];//统计每一列的最小值
}
}
bool flag = false;
for (int i = 0; i < n; i ++ )
for (int j = 0; j < m; j ++ )
if(a[i][j] == r[i] && a[i][j] == l[j]){//如果当前点满足是当前行的最大值,当前列的最小值,就是鞍点
cout << i + 1<< " " << j + 1<< " " << a[i][j] << endl;
flag = true;//标记,存在鞍点
}
if(!flag) cout << "NO" << endl;//不存在鞍点
return 0;
}