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 N*M 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 3*3 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.
Line 1: two integers, N and M(3 <= N, M <= 200).
Line 2~N+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.
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.
8 8 ...HSH.. ...HSM.. ...HST.. ...HSPP. PPGHSPPT PPSSSSSS ..MMSHHH ..MMSH.. SSS SHG SH.
5 4
枚举得让我醉了。。
思路:本题是去求little hi大致在哪里,,可能有多个地点,,然后枚举。。模拟过去。。
AC代码(略挫。。):
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; char map[205][205]; char sur[5][5]; char sur1[5][5]; char sur2[5][5]; char sur3[5][5]; void change(char sur[][5]) //将字符串向右转90度 { char tmp[5][5]; for(int i=0; i<3; i++) for(int j=0; j<3; j++) tmp[i][j] = sur[i][j]; for(int i=0; i<3; i++) sur[i][2] = tmp[0][i]; for(int i=0; i<3; i++) sur[i][1] = tmp[1][i]; for(int i=0; i<3; i++) sur[i][0] = tmp[2][i]; } void create(char sur[][5]) //求出将字符串转90,180,270之后的情况 { for(int i=0; i<3; i++) for(int j=0; j<3; j++) sur1[i][j] = sur[i][j]; change(sur1); for(int i=0; i<3; i++) for(int j=0; j<3; j++) sur2[i][j] = sur1[i][j]; change(sur2); for(int i=0; i<3; i++) for(int j=0; j<3; j++) sur3[i][j] = sur2[i][j]; change(sur3); } int judge(char map[][205], int x, int y, char sur[][5]) //判断是否匹配 { if(map[x-1][y-1] != sur[0][0] || map[x-1][y] != sur[0][1] || map[x-1][y+1] != sur[0][2] || map[x][y-1] != sur[1][0] || map[x][y] != sur[1][1] || map[x][y+1] != sur[1][2] || map[x+1][y-1] != sur[2][0] || map[x+1][y] != sur[2][1] || map[x+1][y+1] != sur[2][2]) return 0; return 1; } int main() { int n, m; while(scanf("%d %d", &n, &m) != EOF) { char surr[11] = ""; for(int i=0; i<n; i++) scanf("%s", map[i]); for(int i=0; i<3; i++) scanf("%s", sur[i]); char center = sur[1][1]; create(sur); for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) if(center == map[i][j]) { if(judge(map, i, j, sur) || judge(map, i, j, sur1) || judge(map, i, j, sur2) || judge(map, i, j, sur3)) printf("%d %d\n", i+1, j+1); } } return 0; }