-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy path1068_万绿丛中一点红(20).cpp
46 lines (43 loc) · 997 Bytes
/
1068_万绿丛中一点红(20).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
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int pic[1005][1005];
unordered_map<int, int> color_count;
int main() {
int m, n, tol;
scanf("%d%d%d", &m, &n, &tol);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &pic[i][j]);
color_count[pic[i][j]] += 1;
}
}
int count = 0;
int posx = -1, posy = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
bool ok = true;
if (color_count[pic[i][j]] != 1) continue;
for (int k = 0; k < 8; k++) {
int nx = i + dx[k];
int ny = j + dy[k];
if (nx >= 0 && nx < n && ny >= 0 && ny < m && abs(pic[i][j] - pic[nx][ny]) <= tol) {
ok = false;
break;
}
}
if (ok) {
count += 1;
posx = i; posy = j;
}
}
}
if (count == 0)
printf("Not Exist\n");
else if (count > 1)
printf("Not Unique\n");
else
printf("(%d, %d): %d\n", posy+1, posx+1, pic[posx][posy]);
return 0;
}