首页 技术 正文
技术 2022年11月21日
0 收藏 701 点赞 4,586 浏览 1032 个字

一开始因为看见这题就头疼,可费了点时间。

要考虑所有元素,如果忽略外圈元素,最后一个样例过不去。

而且要求只出现一次的元素,

我没有使用map,因为当时还没学,用map储存元素会节约好多代码

#include<cstdio>
#include<string.h>
int M,N,TOL;
int arr[1001][1001];
int da[20000000]={0};
int dir[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 + dir[k][0];
int ty = j + dir[k][1];
if (tx >= 0 && tx < M && ty >= 0 && ty < N && arr[i][j] - arr[tx][ty] >= 0 - TOL && arr[i][j] - arr[tx][ty] <= TOL) return false;
}
return true;
}
bool istrue(int i,int j){
long long high=arr[i][j]+TOL;
long long low=arr[i][j]-TOL;
for(int m=i-1;m<(i+2);m++){
for(int n=j-1;n<(j+2);n++){
if(arr[m][n]>=low&&arr[m][n]<=high&&m!=i&&n!=j)
return false;
}
}
return true;
}
int main(){
scanf("%d %d %d",&M,&N,&TOL);
int num=0,data[2];
for(int i=0;i<N;i++){ //input
for(int j=0;j<M;j++){
scanf("%d",&arr[i][j]);
da[arr[i][j]]++;
}
}
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
if(judge(i,j)&&da[arr[i][j]]==1){
if(num==1){
printf("Not Unique");return 0;
}
else{
data[0]=i;data[1]=j;num++;
}
}
}
}
if(num==0){
printf("Not Exist");
}else{
printf("(%d, %d): %d",data[1]+1,data[0]+1,arr[data[0]][data[1]]);
}
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,910
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,435
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,250
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,061
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,693
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,731