HihoCoder-1094-Lost in the City (brute force enumeration !!)
#1094: Lost in the City time limit: Memory ms single point time limit: 256 Ms memory limit: MB
Description
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 mals, '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.
Input
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.
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
-
8 8...HSH.....HSM.....HST.....HSPP.PPGHSPPTPPSSSSSS..MMSHHH..MMSH..SSSSHGSH.
-
Sample output
-
5 4
I'm drunk by enumeration ..
Idea: This question is to find out where little hi is. There may be multiple locations, and then enumerate them .. Simulate the past ..
AC code (slightly frustrated ..) :
# Include
# Include
# Include 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]) // right the string to 90 degrees {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]) // obtain and convert the string Case After 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]) // determines if it matches {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", & n, & m )! = EOF) {char surr [11] = ""; for (int I = 0; I