本文主要是介绍1068. 万绿丛中一点红(20) PAT 乙级,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
传送门
#include<stdio.h>
#include<math.h>
#include<map> using namespace std;#define MAX_N 1100//typedef long long ll;int img[MAX_N][MAX_N];
int m,n;
int tol;map<int,int> v; bool judge(int i,int j){if(v[img[i][j]]!=1)return false;//上if(i>=1)if(abs(img[i][j]-img[i-1][j])<=tol)return false;//下if(i<=n-2)if(abs(img[i][j]-img[i+1][j])<=tol)return false;//左if(j>=1)if(abs(img[i][j]-img[i][j-1])<=tol)return false;//右if(j<=m-2)if(abs(img[i][j]-img[i][j+1])<=tol)return false;//左上if(i>=1&&j>=1)if(abs(img[i][j]-img[i-1][j-1])<=tol)return false;//右上if(i>=1&&j<=m-2)if(abs(img[i][j]-img[i-1][j+1])<=tol)return false;//左下if(i<=n-2&&j>=1)if(abs(img[i][j]-img[i+1][j-1])<=tol)return false;//右下if(i<=n-2&&j<=m-2)if(abs(img[i][j]-img[i+1][j+1])<=tol)return false;return true; }
int main(){scanf("%d%d%d",&m,&n,&tol);for(int i=0;i<n;i++){for(int j=0;j<m;j++){scanf("%d",&img[i][j]);v[img[i][j]]++;}}int pos_i,pos_j;int count=0;for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(judge(i,j)){count++;//printf("%d %d\n",i+1,j+1);pos_i=i;pos_j=j;}}}if(count==0){printf("Not Exist");}if(count==1){printf("(%d, %d): %lld",pos_j+1,pos_i+1,img[pos_i][pos_j]);}if(count>1){printf("Not Unique");}//printf("%d",count);
}
这篇关于1068. 万绿丛中一点红(20) PAT 乙级的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!