题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805265579229184
坑点:
- 题目中的行列和我们输入的行列是相反的,输出也要反着输。
- 条件除了与周围不同以外还有独一无二。
#include <iostream>
#include <map>
using namespace std;
const unsigned maxn = 1005;
int x[maxn][maxn];
map <int, int>pp;
void solve()
{
int m, n, k;
cin>>n>>m>>k;
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
{
cin>>x[i][j];
pp[x[i][j]]++;
}
int r[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1},{1, -1}, {1, 0}, {1, 1}};
int re[2];
int co = 0;
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
bool fa = true;
if(pp[x[i][j]] > 1)
continue;
for(int h = 0; h < 8; h++)
{
int a = -1, b = -1;
if(r[h][0] + i >= 0 && r[h][0] + i < m)
a = r[h][0] + i;
if(r[h][1] + j >= 0 && r[h][1] + j < n)
b = r[h][1] + j;
if(a != -1 && b != -1)
{
int mm = x[a][b] - x[i][j];
if(mm < 0)
mm *= -1;
if(mm <= k)
{
fa = false;
break;
}
}
}
if(fa)
{
co++;
re[0] = i;
re[1] = j;
}
if(co > 1)
break;
}
if(co > 1)
break;
}
if(co == 1)
cout<<"("<<re[1] + 1<<", "<<re[0] + 1<<"): "<<x[re[0]][re[1]]<<endl;
else if(co == 0)
cout<<"Not Exist"<<endl;
else
cout<<"Not Unique"<<endl;
return;
}
int main()
{
solve();
return 0;
}
20分一般类,注意细节
2018年9月17日 15:58:07