编程介的小学生 2019-09-14 23:52 采纳率: 20.5%
浏览 57

Street Crossing 算法的实现的技术

Description

In an amusement park, there is a street covered by hexagonal shaped ceramic bricks. The bricks are wired from underground, in a strange way such that each brick can become hot or cold during one second, and remain in the same hot/cold state or change in the next step depending on its adjacent bricks. A special technology is used in manufacturing these ceramics so that it can abruptly change state from cold to hot or visa versa.

The initial pattern of hot/cold states of each brick is given. From this information and the following rules, one can find out whether a particular brick is cold or hot at any one-second duration in future. The bricks become hot or cold according to the following rules:

If a brick is hot at second t, it will become cold at second t + 1, if it has exactly 3 cold bricks among its adjacent bricks, otherwise it remains hot.
If a brick is cold at second t, it remains cold at second t + 1, if it has 2 or 3 cold bricks among its adjacent bricks, otherwise it will become hot in the second t + 1.

The game starts when one jumps to one of the bricks on the first row close to the border of the street, and the time is reset to zero. The participant can stay on the same brick during the next one-second time stamp, or jump to one of its adjacent bricks at the start of the next second. It is not allowed to jump over the bricks. Obviously, a participant can only step on the cold bricks. You are to write a program to help a participant cross this street in a minimum amount of time.
Input

The first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains two integers: N (1 <= N <= 10), the number of rows of the bricks, and M (1 <= M <= 10), the number of bricks in the each row. The brick (i, j) is the jth brick on the ith row counting from left to right. The rows are counted from 1 to N starting from the side of the street that the participant starts from (Figure 1). Note that for boundary bricks, the adjacent bricks may be less than 6, which is the number of adjacent bricks for the interior bricks. Followed by the first line, there will be N lines, each containing a string of length M, consisting of upper-case letters 'H' and 'C'. A 'C' at position j in the ith string means that the brick (i, j) is cold at time 0, and an 'H' means the brick is hot at that time.

Output

There should be one line in output per test case, containing either a number t which is the minimum time at which time a participant can steps on the other side of the street, or the word impossible, if it is not possible to reach to the other side, or the minimum required time is greater than 1000.
Sample Input

2
2 2
CH
CC
2 2
CH
HC
Sample Output

2
impossible

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛