-
Notifications
You must be signed in to change notification settings - Fork 0
/
test34.cpp
48 lines (45 loc) · 1.1 KB
/
test34.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<algorithm>
#include<ctype.h>
#include<string>
#include<map>
#include<utility>
using namespace std;
pair<int, int> find_saddle_point(vector<vector<int>>& A) {
int m = A.size();
int n = A[0].size();
vector<int> rowMin(m);
vector<int> colMax(n);
for (int i = 0; i < m; i++) {
rowMin[i] = *min_element(A[i].begin(), A[i].end());
}
for (int j = 0; j < n; j++) {
colMax[j] = A[0][j];
for (int i = 1; i < m; i++) {
colMax[j] = max(colMax[j], A[i][j]);
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (A[i][j] == rowMin[i] && A[i][j] == colMax[j]) {
return { i, j };
}
}
}
return { -1, -1 };
}
int main()
{
vector<vector<int>> A{
{1,2545,3,4,5,6},
{12,2554,23,24,5,6},
{12,2555,3,24,5,6},
{21,288,3,24,5,6},
{21,256,23,4,5,6},
{21,25454,3,4,5,6},
};
pair<int, int> ans = find_saddle_point(A);
cout << ans.first << " " << ans.second << endl;
}