hihocoder-#1094 : Lost in the City

#1094 : Lost in the City

时间限制: 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
解答
首先初始化先将数据读入:
 string[] mn = (Console.ReadLine()).Split(' ');
            int n = Convert.ToInt32(mn[0]);
            int m = Convert.ToInt32(mn[1]);
            string[,] map = new string[n,m];
            string[,] pos = new string[3, 3];
            //init
            for (int i = 0; i < n; i++)
            {
                string temp = Console.ReadLine();
                for (int j = 0; j < m; j++)
                {
                    map[i,j] = temp[j].ToString();
                }
            }
            for (int i = 0; i < 3; i++)
            {
                string temp = Console.ReadLine();
                for (int j = 0; j < 3; j++)
                {
                    pos[i,j] = temp[j].ToString();
                }
            }
接下来的方法用了特别的字符串比较技巧 首先要明确我们的目标其实是比较pos(3*3)矩阵跟我们遍历的每一个地图上的3*3矩阵是不是旋转关系。如果把“地图”旋转之后能与所在位置pos吻合就ok 核心部分:
string source = pos[0, 0] + pos[0, 1] + pos[0, 2] + pos[1, 2] + pos[2, 2] + pos[2, 1] + pos[2, 0] + pos[1, 0];
            for (int i = 1; i < n - 1; i++)
            {
                for (int j = 1; j < m - 1; j++)
                {
                    if (map[i,j] == pos[1,1])
                    {
                        string part = map[i - 1, j - 1] + map[i - 1, j] + map[i - 1, j + 1] + map[i, j + 1] + map[i + 1, j + 1] + map[i + 1, j] + map[i + 1, j - 1] + map[i, j - 1];
                        part += part;
                        if (part.Contains(source))
                            Console.WriteLine(string.Format("{0} {1}", i + 1, j + 1));
                    }
                }
            }

———————— 这是昨天想到的办法,居然通过了test。但是今天细想一下发现用的技巧有bug,所以是怎么回事呢?hihocoder平台错了?
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值