时间限制: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
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[n];
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;
}
}

  

#1094 : Lost in the City的更多相关文章

  1. hihoCoder #1094 : Lost in the City(枚举,微软苏州校招笔试 12月27日 )

    #1094 : Lost in the City 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He ...

  2. hihocoder #1094 : Lost in the City微软苏州校招笔试 12月27日 (建图不大【暴力枚举】 子图的4种形态 1Y )

    #1094 : Lost in the City 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He ...

  3. #1094 : Lost in the City by C solution

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He does not know where he is ...

  4. hihoCoder#1094 Lost in the City

    原题地址 限时10s,所以不用考虑什么算法了,暴力吧 分别按照3x3视野的四个方向去地图上匹配,把符合的地点标记出来,最后统一按照从上到下,从左到右的顺序输出. 代码: #include <io ...

  5. BZOJ 2001: [Hnoi2010]City 城市建设

    2001: [Hnoi2010]City 城市建设 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 1132  Solved: 555[Submit][ ...

  6. History lives on in this distinguished Polish city II 2017/1/5

    原文 Some fresh air After your time underground,you can return to ground level or maybe even a little ...

  7. History lives on in this distinguished Polish city 2017/1/4

    原文 History lives on in this distinguished Polish city Though it may be ancient. KraKow, Poland, is a ...

  8. GeoIP Legacy City数据库安装说明

    Here is a brief outline of the steps needed to install GeoIP Legacy City on Linux/Unix. The installa ...

  9. hihoCoder#1094

    刚开始学习C语言,准备在做hiho的题目的过程中来学习,在此进行记录,如果代码中有错误或者不当的地方还请指正. 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Littl ...

随机推荐

  1. POI完美解析Excel数据到对象集合中(可用于将EXCEL数据导入到数据库)

    实现思路: 1.获取WorkBook对象,在这里使用WorkbookFactory.create(is); // 这种方式解析Excel.2003/2007/2010都没问题: 2.对行数据进行解析 ...

  2. 如何在eclipse中通过Juit进行单元测试

    1.什么是Junit Junit即单元测试,是JAVA语言的单元测试框架,是对程序的一个方法所进行的测试 一般都是由程序员自己通过Junit来进行测试,因此单元测试也叫程序员测试: 如果测试人员熟悉程 ...

  3. hadoop2.6.4 搭建单机模式

    注(要先安装jdk,最好jdk版本>=1.7) 安装jdk  http://www.cnblogs.com/zhangXingSheng/p/6228432.html     给普通用户添加su ...

  4. javaScript里的原型链

    原型对象也是普通的对象,是对象一个自带隐式的__proto__属性,原型也有可能有自己的原型,如果一个原型对象的原型不为null的话,我们就称之为原型链.原型链是由一些用来继承和共享属性的对象组成的( ...

  5. Linux学习日记之磁盘与档案系统

    主要定义 磁盘的物理组成磁盘主要由圆形磁盘(多张).机械手臂.磁头等组成.每张磁盘都有不同的磁道,半径相同的磁道组成了磁柱,沿着中心划线可将磁盘分成若干扇区,每个扇区的大小是512Bytes. 磁盘分 ...

  6. 第一次使用UML的感觉

    刚开始接触的时候,其实我内心是拒绝的,因为感觉这种软件之前接触过,觉得就是相当于思维导图那种的. 可当自己使用的时候,觉得大纲总体上是类似是规划方向的,可是细节却让人深思,用什么图标,特别是用什么线, ...

  7. 【Java EE 学习 70 上】【数据采集系统第二天】【数据加密处理】【登陆验证】【登陆拦截器】【新建调查】【查询调查】

    一.数据加密处理 这里使用MD5加密处理,使用java中自带加密工具类MessageDigest. 该类有一个方法digest,该方法输入参数是一个字符串返回值是一个长度为16的字节数组.最关键的是需 ...

  8. shell循环语句

    所有的笔记只记录一些例子,根据例子解释一些出现的语法,不介绍具体的语法 2015-07-01 21:58:33 星期三 for循环 用例一用for循环在家目录下创建aaa1-aaa10,然后在aaa1 ...

  9. 怎样用conda安装opencv

    首先用Anaconda是因为方便(管理方便,包安装真心不方便).下面是我的安装过程: 首先使用如下命令安装opencv conda install -c https://conda.binstar.o ...

  10. Mac下没有权限启动tomcat的解决办法

    问题描述 在Mac中通过./startup.sh执行启动脚本文件,启动tomcat时报如下错误: -bash: ./startup.sh: Permission denied 解决方法 错误信息说明了 ...