码迷,mamicode.com
首页 > 其他好文 > 详细

hihoCoder#1094

时间:2015-10-02 22:21:50      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:

 

刚开始学习C语言,准备在做hiho的题目的过程中来学习,在此进行记录,如果代码中有错误或者不当的地方还请指正。

 

时间限制: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

解决思路

从(2,2)开始到(n-1,m-1)的方块中的每一个元素进行分析,看其是否满足。分析元素过程:首先顺时针

分析离得最近的四个如果满足,再顺时针分析四个角上的是否满足(注意一旦四个最近的顺序确定了

那么四个角上的顺序也就定下来了)。最后输出所有满足条件的结果。

 

hihoCoder#1094

标签:

原文地址:http://www.cnblogs.com/ZH-0/p/4852764.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!