Time limit:10000msSingle Point time limit:1000msMemory Limit:256MB
Describe
Little Hi gets lost in the city. He does not know where he is. He does not know which direction was north.
Fortunately, Little Hi have a map of the city. The map can be considered as a grid of n*m blocks. Each block was numbered by a pair of integers. The block at the north-west Corner are (1, 1) and the one at the South-east Corner is (N, M). Each block was 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 the surrounding Little hi (Little hi are at the middle block of the 3*3 area), please find out The position of him. Note that Little Hi was disoriented, the upper side of the surrounding area could be actually north side, South side, East Si De 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 is ' 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 the block (X, Y) may be Little Hi ' s position. If there is 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
Import Java.util.priorityqueue;import Java.util.scanner;public class Main {private Boolean ishere (char[][] Hi, char[][] CityMap, int row, int column) {if (hi[1][1]! = Citymap[row][column]) return False;boolean res = true;for (int i = 0; i < 3; i++) {for (int j = 0; J < 3; J + +) {if (hi[i][j]! = citymap[row + I-1][column + j-1]) {return false;}} return true;} public static void Main (String args[]) {class Pair implements Comparable{int x, y; Pair (int x,int y) {this.x = X;this.y = y;} @Overridepublic int compareTo (Object o) {pair other = (pair) o;if (this.x==other.x) {return this.y-other.y;} TODO auto-generated method Stubreturn this.x-other.x;}} /*scanner sc = null;try {sc = new Scanner (New FileInputStream ("D:\\desktop\\test.txt"));} catch (FileNotFoundException e) {//TODO auto-generated catch Blocke.printstacktrace ();} */scanner sc = new Scanner (system.in); Main main = new main (); int row = Sc.nextint (); int column = Sc.nextint (); char [][]citymap = new Char[row][column];for (int i =0;i<row;i++) {String str = sc.next (); for (int j=0;j<column;j++) {citymap[i][j]= Str.charat (j);}} char[][] Hi1 = new char[3][3];char[][] Hi2 = new char[3][3];char[][] Hi3 = new char[3][3];char[][] Hi4 = new CHAR[3][3];FO R (int i=0;i<3;i++) {String str = sc.next (); for (int j=0;j<3;j++) {char c = Str.charat (j); Hi1[i][j] = c;hi2[2-i][2-j] = C;hi3[2-j][i] =c;hi4[j][2-i] =c;}} Priorityqueue<pair> PQ = new priorityqueue<> (); for (int. i=1;i<row-1;i++) {for (int j=1;j<column-1;j++ ) {if (Main.ishere (Hi1, CityMap, I, j) | | Main.ishere (Hi2, CityMap, I, j) | | Main.ishere (Hi3, CityMap, I, j) | | Main.ishere (Hi4, CityMap, I, J)) {Pq.add (new Pair (I,J));}}} Pair p = pq.poll (), while (P!=null) {System.out.println ((p.x+1) + "+ (p.y+1));p = Pq.poll ();}}}
[Hihocoder] #1094: Lost in the city Microsoft Suzhou School Recruitment Test December 27