标签:
刚开始学习C语言,准备在做hiho的题目的过程中来学习,在此进行记录,如果代码中有错误或者不当的地方还请指正。
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.
从(2,2)开始到(n-1,m-1)的方块中的每一个元素进行分析,看其是否满足。分析元素过程:首先顺时针
分析离得最近的四个如果满足,再顺时针分析四个角上的是否满足(注意一旦四个最近的顺序确定了
那么四个角上的顺序也就定下来了)。最后输出所有满足条件的结果。
标签:
原文地址:http://www.cnblogs.com/ZH-0/p/4852764.html