hihocoder 1094 : Lost in the City

时间限制: 10000ms
单点时限: 1000ms
内存限制: 256MB

描述

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

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main=new Main();
		Scanner scan=new Scanner(System.in);
		int x=scan.nextInt();
		int y=scan.nextInt();
		char[][] map=new char[x][y];
		for(int i=0;i<x;i++){
			String str=scan.next();
			for(int j=0;j<y;j++){
				map[i][j]=str.charAt(j);
			}
		}
		char[][] arr=new char[3][3];
		for(int i=0;i<3;i++){
			String str=scan.next();
			for(int j=0;j<3;j++){
				arr[i][j]=str.charAt(j);
			}
		}
		main.solve(map,arr);
	}
	private void solve(char[][] map, char[][] arr) {
		List<char[][]> template=getTemplate(arr);
		for(int i=0;i<=map.length-3;i++){
			for(int j=0;j<=map[0].length-3;j++){
				for(char[][] temp:template){
					if(isSame(map,i,j,temp)){
						System.out.println((i+2)+" "+(j+2));
						break;
					}
				}
			}
		}
	}
	private boolean isSame(char[][] map, int i, int j, char[][] arr) {
		for(int k=0;k<arr.length;k++){
			for(int l=0;l<arr[0].length;l++){
				if(map[i+k][j+l]!=arr[k][l]) return false;
			}
		}
		return true;
	}
	public List<char[][]> getTemplate(char[][] arr){
		List<char[][]> re=new ArrayList<char[][]>();
		re.add(arr);
		for(int i=0;i<3;i++){
			arr=rotateRight(arr);
			re.add(arr);
		}
		return re;
	}
	public char[][] rotateRight(char[][] arr){
		char[][] arr2=new char[3][3];
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				arr2[j][2-i]=arr[i][j];
			}
		}
		return arr2;
	}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值