#1094 : Lost in the City
2016-04-29 10:06
417 查看
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
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 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.
样例输入
样例输出
单点时限: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
package com.oj; import java.util.Scanner; public class TestValueOf { public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] NM = in.nextLine().split(" "); int n = Integer.parseInt(NM[0]); int m = Integer.parseInt(NM[1]); String[] map = new String ; for(int i = 0;i < n; i++){ map[i] = in.nextLine(); } String[] posIn = new String[3]; for(int i = 0;i < 3; i++) posIn[i] = in.nextLine(); StringBuilder sb = new StringBuilder(); sb.append(posIn[0]).append(posIn[1]).append(posIn[2]); for(int i = 1;i < m-1; i++) for(int j = 1;j < n-1; j++) if(FindPos(i,j,map,sb.toString())){ System.out.println((i+1)+" "+(j+1)); //return ; } } private static boolean FindPos(int i, int j, String[] map, String environment) { //System.out.println(i+" "+j); StringBuilder dir = new StringBuilder(); dir.append(map[i-1].substring(j-1, j+2)); dir.append(map[i].substring(j-1, j+2)); dir.append(map[i+1].substring(j-1, j+2)); //System.out.println("1: "+dir.toString()); if(dir.toString().equals(environment)) return true; StringBuilder dir2 = new StringBuilder(); dir2.append(map[i-1].charAt(j+1)).append(map[i].charAt(j+1)).append(map[i+1].charAt(j+1)); dir2.append(map[i-1].charAt(j)).append(map[i].charAt(j)).append(map[i+1].charAt(j)); dir2.append(map[i-1].charAt(j-1)).append(map[i].charAt(j-1)).append(map[i+1].charAt(j-1)); //System.out.println("2: "+dir2.toString()); if(dir2.toString().equals(environment)) return true; StringBuilder dir3 = new StringBuilder(); dir3.append(new StringBuilder(map[i+1].substring(j-1, j+2)).reverse()); dir3.append(new StringBuilder(map[i].substring(j-1, j+2)).reverse()); dir3.append(new StringBuilder(map[i-1].substring(j-1, j+2)).reverse()); //System.out.println("3: "+dir3.toString()); if(dir3.toString().equals(environment)) return true; StringBuilder dir4 = new StringBuilder(); dir4.append(map[i+1].charAt(j-1)).append(map[i].charAt(j-1)).append(map[i-1].charAt(j-1)); dir4.append(map[i+1].charAt(j)).append(map[i].charAt(j)).append(map[i-1].charAt(j)); dir4.append(map[i+1].charAt(j+1)).append(map[i].charAt(j+1)).append(map[i-1].charAt(j+1)); //System.out.println("4: "+dir4.toString()); if(dir4.toString().equals(environment)) return true; return false; } }
相关文章推荐
- nodejs forever
- 设计模式学习第八天
- centOS7.2.1511 bit64位 浏览器不能上网
- 乱码问题
- Vim bundle
- C语言字符串结束符
- 使用C#的HttpWebRequest模拟登陆网站
- 1. windows下作为应用程序启动apache的方法
- zabbix 界面翻译不完全的处理
- 开根号几种写法
- 佩尔方程的最小解
- JavaScript函数柯里化详解
- 线程中sleep和wait的区别
- POJ_2392_Space_Elevator_(动态规划,背包)
- URLEncode和URLDecode的注意事项
- JAVA回调机制(CallBack)详解
- 记录一次多线程死锁的问题
- Maven学习之利用mvn deploy命令上传包
- 线上服务 静态html CMS 发布rsync 同步
- java程序的工作原理