AcWing 3708. 求矩阵的鞍点
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 10;
int t, n, m, k, l, r, op, x, y;
int f[N][N];
unordered_set<int>st;
vector<pii> ans;
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int hmax = 0;
vector<int> p;
for (int j = 1; j <= m; j++) {
cin >> f[i][j];
if (f[i][j] > hmax) {
p.clear();
p.push_back(j);
hmax = f[i][j];
} else if (f[i][j] == hmax) {
p.push_back(j);
}
}
for (int num : p) {
st.insert(i * N + num);
}
}
for (int i = 1; i <= m; i++) {
int lmax = 0x3f3f3f3f;
vector<int> p;
for (int j = 1; j <= n; j++) {
if (f[j][i] < lmax) {
p.clear();
p.push_back(j);
lmax = f[j][i];
} else if (f[j][i] == lmax) {
p.push_back(j);
}
}
for (int num : p) {
if (st.find(num * N + i) != st.end()) {
ans.push_back({num, i});
}
}
}
if (ans.size()) {
sort(ans.begin(),ans.end());
for(auto[x,y]:ans){
cout<<x<<" "<<y<<" "<<f[x][y]<<"\n";
}
} else {
cout << "NO";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}