Lost in the City
Time Limit: 10 Sec Memory Limit: 256 MB
描述
Little Hi gets lost in the city. He does not know where he is. He does not know which direction is north.
Fortunately, Little Hi has a map of the city. The map can be considered as a grid of NxM blocks. Each block is numbered by a pair of integers. The block at the north-west corner is (1, 1) and the one at the south-east corner is (N, M). Each block is represented by a character, describing the construction on that block: ‘.’ for empty area, ‘P’ for parks, ‘H’ for houses, ‘S’ for streets, ‘M’ for malls, ‘G’ for government buildings, ‘T’ for trees and etc.
Given the blocks of 3x3 area that surrounding Little Hi(Little Hi is at the middle block of the 3*3 area), please find out the position of him. Note that Little Hi is disoriented, the upper side of the surrounding area may be actually north side, south side, east side or west side.

传送门:HIHO1094

Input

Line 1: two integers, N and M(3 <= N, M <= 200).
Line 2N+1: each line contains M characters, describing the city’s map. The characters can only be ‘A’-‘Z’ or ‘.’.
Line N+2
N+4: each line 3 characters, describing the area surrounding Little Hi.

Output

Line 1~K: each line contains 2 integers X and Y, indicating that block (X, Y) may be Little Hi’s position. If there are multiple possible blocks, output them from north to south, west to east.

Sample Input

1
2
3
4
5
6
7
8
9
10
11
12
8 8
...HSH..
...HSM..
...HST..
...HSPP.
PPGHSPPT
PPSSSSSS
..MMSHHH
..MMSH..
SSS
SHG
SH.

Sample Output

1
5 4

题解

好恶心的题 以后请叫我枚举王 MDZZ只要枚举四个方向的矩阵然后慢慢判就行了。。。
## AC code:(不包含输入类)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.io.*;  
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
int m=sc.nextInt();
sc.nextLine();
String cur;
char [][]maze=new char [n+1][m+1];
for(int i=1;i<=n;i++){
cur=sc.nextLine();
for(int j=1;j<=m;j++){
maze[i][j]=cur.charAt(j-1);
}
}
//枚举四个方向
char[][] target =new char [3][3];
char[][] targetl =new char [3][3];
char[][] targetr =new char [3][3];
char[][] targetd =new char [3][3];
for(int i=0;i<3;i++){
cur=sc.nextLine();
for(int j=0;j<3;j++){
target[i][j]=cur.charAt(j);
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
targetl[i][j]=target[2-j][i];
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
targetr[i][j]=target[j][2-i];
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
targetd[i][j]=target[2-i][2-j];
}
}
/*for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(targetd[i][j]);
}
System.out.print('\n');
}*/
for(int i=2;i<=n-1;i++){
for(int j=2;j<=m-1;j++){
int [][]step={{-1,-1},{-1,0},{-1,1},{0,-1},{0,0},{0,1},{1,-1},{1,0},{1,1}};
int k=0;
for(k=0;k<9;k++){
if(maze[i+step[k][0]][j+step[k][1]]!=target[1+step[k][0]][1+step[k][1]]){
break;
}
}
if(k==9){
System.out.println(i+" "+j);
}else{
for(k=0;k<9;k++){
if(maze[i+step[k][0]][j+step[k][1]]!=targetl[1+step[k][0]][1+step[k][1]]){
break;
}
}
if(k==9){
System.out.println(i+" "+j);
}
else{
for(k=0;k<9;k++){
if(maze[i+step[k][0]][j+step[k][1]]!=targetr[1+step[k][0]][1+step[k][1]]){
break;
}
}
if(k==9){
System.out.println(i+" "+j);
break;
}
else{
for(k=0;k<9;k++){
if(maze[i+step[k][0]][j+step[k][1]]!=targetd[1+step[k][0]][1+step[k][1]]){
break;
}
}
if(k==9){
System.out.println(i+" "+j);
}
}
}
}
}
}
}
}
}