-
Notifications
You must be signed in to change notification settings - Fork 2
/
B1068.cpp
65 lines (62 loc) · 1.86 KB
/
B1068.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*************************************************************************
> File Name: B1068.cpp
> Author: bumzy
> Mail: [email protected]
> Created Time: 2017年07月30日 星期日 21时31分14秒
************************************************************************/
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <unordered_map>
using namespace std;
const int MAXN = 1000 + 10;
int matrix[MAXN][MAXN];
const int step[8][2] = {-1, -1,
-1, 0,
-1, 1,
0, -1,
0, 1,
1, -1,
1, 0,
1, 1};
int main() {
int m, n, tol;
unordered_map<int, int> M;
scanf("%d%d%d", &m, &n, &tol);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
scanf("%d", &matrix[i][j]);
M[matrix[i][j]]++;
}
}
vector<pair<int, int>> result;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
bool flag = true;
for (int k = 0; k < 8; ++k) {
int x = i + step[k][0];
int y = j + step[k][1];
if (x >= 0 && x < n && y >= 0 && y < m) {
if (abs(matrix[x][y] - matrix[i][j]) <= tol) {
flag = false;
break;
}
}
}
if (flag == true && M[matrix[i][j]] == 1) {
result.push_back(make_pair(i, j));
}
}
}
if (result.size() == 0) {
printf("Not Exist\n");
} else if (result.size() == 1) {
int x = result[0].first + 1;
int y = result[0].second + 1;
printf("(%d, %d): %d\n", y, x, matrix[x - 1][y - 1]);
} else {
printf("Not Unique\n");
}
return 0;
}