solution
- 找出满足①像素值唯一&②和相邻像素点色差大于tol 的像素点个数
- 若唯一,则输出该像素点列、行、像素值;
- 若不唯一,则输出"Not Unique"
- 若无,则输出"Not Exist"
- 题干和输出中,都是先列再行
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1010;
ll a[maxn][maxn];
int main(){
int m, n, cnt = 0, flag, x, y;
ll tol, color;
map<ll, int> mp;
scanf("%d%d%lld", &m, &n, &tol);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
scanf("%lld", &a[i][j]);
mp[a[i][j]]++;
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
flag = 0;
if(mp[a[i][j]] == 1){
for(int k = i - 1; k <= i + 1 && !flag; k++){
for(int l = j - 1; l <= j + 1 && !flag; l++){
if(k < 1 || k > n || l < 1 || l > m || (k == i && l == j)) continue;
if(abs(a[i][j] - a[k][l]) <= tol) flag = 1;
}
}
if(!flag) {
cnt++;
x = j;
y = i;
color = a[i][j];
}
}
}
}
if(!cnt) printf("Not Exist");
else if(cnt > 1) printf("Not Unique");
else printf("(%d, %d): %lld", x, y, color);
return 0;
}