-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1068.cpp
More file actions
89 lines (79 loc) · 1.71 KB
/
1068.cpp
File metadata and controls
89 lines (79 loc) · 1.71 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<iostream>
#include<map>
#include<cmath>
using namespace std;
//判断该点的颜色与其周围 8 个相邻像素的颜色差是否充分大
bool isRed(int i, int j, int v[][1002], int tol) {
if (abs(v[i - 1][j - 1] - v[i][j]) <= tol) { // 左上角
return false;
}
if (abs(v[i][j - 1] - v[i][j]) <= tol) { // 上
return false;
}
if (abs(v[i + 1][j - 1] - v[i][j]) <= tol) { // 右上角
return false;
}
if (abs(v[i + 1][j] - v[i][j]) <= tol) { // 右
return false;
}
if (abs(v[i + 1][j + 1] - v[i][j]) <= tol) { // 右下角
return false;
}
if (abs(v[i][j + 1] - v[i][j]) <= tol) { // 下
return false;
}
if (abs(v[i - 1][j + 1] - v[i][j]) <= tol) { // 左下角
return false;
}
if (abs(v[i - 1][j] - v[i][j]) <= tol) { // 左
return false;
}
else
return true;
}
int main()
{
int m, n, x,y,tol, flag = 0;
map<int, int> count;//记录每个颜色出现的次数
//开大两个长度,这道题很坑,必须判断边缘的颜色情况,且对于边缘像素来说,只需判断它的八个方位中存在
//像素点,不存在的默认像素差充分大
int c[1002][1002] = { 0 };
cin >> m >> n >> tol;
//初始化像素值很小,保证对于边缘像素来说其不存在的方位上像素差充分大
for (int i = 0; i < 1002; i++)
{
for (int j = 0; j < 1002; j++)
c[i][j] = -10000000;
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
scanf("%d", &c[i][j]);
count[c[i][j]]++;
}
}
for (int i = 1; i <= n ; i++)
{
for (int j = 1; j <= m ; j++)
{
if (count[c[i][j]] == 1&&isRed(i,j,c,tol))//满足条件
{
flag++;
x = i;
y = j;
}
if (flag > 1)//有超过一个满足条件的像素点
break;
}
if (flag > 1)
break;
}
if (flag == 0)
cout << "Not Exist\n";
else if (flag == 1)
printf("(%d, %d): %d\n", y, x, c[x][y]);
else
cout << "Not Unique\n";
return 0;
}