-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI068.java
More file actions
56 lines (51 loc) · 1.93 KB
/
I068.java
File metadata and controls
56 lines (51 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package levelB;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
public class I068 {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] str=br.readLine().split(" ");
int M=Integer.parseInt(str[0]);//M列
int N=Integer.parseInt(str[1]);//N行
int TOL=Integer.parseInt(str[2]);
HashMap<Integer,Integer> map=new HashMap<>();
int px[][]=new int[N][M];
for(int i=0;i<N;i++){
String[] temp=br.readLine().split("\\s+");
for(int j=0;j<M;j++){
px[i][j]=Integer.parseInt(temp[j]);
if(map.containsKey(px[i][j]))
map.put(px[i][j],map.get(px[i][j])+1);
else
map.put(px[i][j],1);
}
}
int count=0,x=0,y=0;
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
if(map.get(px[i][j])==1&&judge(px,i,j,TOL,M,N)){
count++;
x=i;
y=j;
}
}
}
if(count==0)
System.out.print("Not Exist");
else if(count==1)//(5, 3): 16711680
System.out.print("("+(y+1)+", "+(x+1)+"): "+px[x][y]);
else
System.out.print("Not Unique");
}
public static boolean judge(int[][] px,int x,int y,int TOL,int M,int N){
int[][] coordinate={{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1}};
for(int i=0;i<8;i++){
int coordinate_x=x+coordinate[i][0];
int coordinate_y=y+coordinate[i][1];
if(coordinate_x>=0&&coordinate_x<N&&coordinate_y>=0&&coordinate_y<M&&Math.abs(px[x][y]-px[coordinate_x][coordinate_y])<=TOL)
return false;
}
return true;
}
}