hihocoder 1094 : Lost in the City
2017-07-24 18:42
369 查看
时间限制: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.
样例输入
样例输出
5 4
单点时限: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; } }
相关文章推荐
- hihocoder-#1094 : Lost in the City
- hihoCoder题库1094Lost in the City
- 【hihocoder】1094. lost in the City
- 【hihocoder】#1094 : Lost in the City
- #1094 : Lost in the City 找到几个当年c语言留下的坑
- hihoCoder #1094 : Lost in the City
- [HIHO1094]Lost in the City(暴力、枚举)
- #1094 : Lost in the City 找到几个当年c语言留下的坑
- hihocoder #1094 : Lost in the City微软苏州校招笔试 12月27日 (建图不大【暴力枚举】 子图的4种形态 1Y )
- #1094 : Lost in the City
- hihocoder#1094 Lost in the City
- hiho #1094 : Lost in the City
- hihocoder #1094 : Lost in the City
- #1094 : Lost in the City(测试用例正确,但提交显示WA,求发现我程序错误)
- #1094 Lost in the City
- HIHOCODER#1094 : Lost in the City
- #1094 : Lost in the City
- hihocoder 第68周 题目1 : Lost in the City
- hihocoder #1094 : Lost in the City
- #1094 : Lost in the City