“人其实就这一辈子,我想要的生活不是安逸的,虽然很累,但我想要辉煌的人生,所以也一直在为此努力、不松懈。我所理解的辉煌人生,不是挣了多少钱、做了多伟大的事,而是将人生过得有意义,不碌碌无为。哪怕前进得很慢,但是每分每秒都在往前走,去追求梦想。” ----喻言
对于计算机而言,颜色不过是像素点对应的一个 24 位的数值。现给定一幅分辨率为 M×N 的画,要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点的颜色与其周围 8 个相邻像素的颜色差充分大。
输入格式:
输入第一行给出三个正整数,分别是 M 和 N(≤ 1000),即图像的分辨率;以及 TOL,是所求像素点与相邻点的颜色差阈值,色差超过 TOL 的点才被考虑。随后 N 行,每行给出 M 个像素的颜色值,范围在 [0,224) 内。所有同行数字间用空格或 TAB 分开。
输出格式:
在一行中按照 (x, y): color
的格式输出所求像素点的位置以及颜色值,其中位置 x
和 y
分别是该像素在图像矩阵中的列、行编号(从 1 开始编号)。如果这样的点不唯一,则输出 Not Unique
;如果这样的点不存在,则输出 Not Exist
。
输入样例 1:
8 6 200
0 0 0 0 0 0 0 0
65280 65280 65280 16711479 65280 65280 65280 65280
16711479 65280 65280 65280 16711680 65280 65280 65280
65280 65280 65280 65280 65280 65280 165280 165280
65280 65280 16777015 65280 65280 165280 65480 165280
16777215 16777215 16777215 16777215 16777215 16777215 16777215 16777215
输出样例 1:
(5, 3): 16711680
输入样例 2:
4 5 2
0 0 0 0
0 0 3 0
0 0 0 0
0 5 0 0
0 0 0 0
输出样例 2:
Not Unique
输入样例 3:
3 3 5
1 2 3
3 4 5
5 6 7
输出样例 3:
Not Exist
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include <numeric>
#include<unordered_set>
#include <climits>//INT_100010n
//#include<bits/stdc++.h>
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define INF 0x7fffffff;
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
#define PI 3.1415926
#define LL unsigned int
#define mod 1000000007
#define wc 1e-18
typedef long long ll;
using namespace std;
int m, n, tt;
int ct, x, y;
vector<vector<int>> v;
int df[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}};
bool judge(int i, int j)
{
for (int k = 0; k < 8; k++)
{
int tx = i + df[k][0];
int ty = j + df[k][1];
if (tx >= 0 && tx < n && ty >= 0 && ty < m && v[i][j] - v[tx][ty] >= 0 - tt && v[i][j] - v[tx][ty] <= tt)
return false;
}
return true;
}
int main()
{
scanf("%d%d%d", &m, &n, &tt);
v.resize(n, vector<int>(m));
map<int, int> mp;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
scanf("%d", &v[i][j]);
mp[v[i][j]]++;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (mp[v[i][j]] == 1 && judge(i, j) == true)
{
ct++;
x = i + 1;
y = j + 1;
}
}
}
if (ct == 1)
printf("(%d, %d): %d", y, x, v[x-1][y-1]);
else if (ct == 0)
printf("Not Exist");
else
printf("Not Unique");
return 0;
}