编程介的小学生 2019-06-06 22:14 采纳率: 20.5%
浏览 162

以最少的移动次数将冰人移动到目的地的程序用C语言的程序的代码编程的实现的正确的做法是什么

Problem Description
Iceman was in a room in Iceland. He wants to get out of it, but it's not as easy as it seems. To help him, you need to know something about Iceland and Iceman.

The room could be described by an n*m grid, so there are n rows numbered 1 to n from top to bottom, each with m squares numbered 1 to m from left to right. Each square may be empty, icy or rocky. An empty square is denoted by '.', while a rocky square is denoted by 'X'. Ice squares are a bit complex, so we talk about it later. The first and last rows and columns are all rocky. The iceman's initial location is always an empty square at the beginning, denoted by '@'. His destination is also empty at the beginning, denoted by '#'. What's more, the destination is always directly above a rocky square. Though the iceman looks bigger than a square, he always occupies exactly one single empty square. The iceman has four kinds of moves: go left (L), go right (R), magic wind left (<) and magic wind right (>). Suppose the
iceman is at (r, c), then '<' move operates on the iceman's bottom-left square (r+1, c-1). If the square is rocky, the move does nothing; if the square is empty, it becomes icy; if the square is icy, it becomes empty. There are four kinds of icy squares: ice with two free-ends (O), ice with left free-end ([), ice with right free-end (]), ice with no free-end (=). Here 'free' means 'not connected'. If an icy square is created by a magic-wind move, it connects to its left/right neighbor, provided the corresponding neighboring square is not empty (rocky or icy). The connections between neighboring
squares are symmetric, so squares that are connected to each other behave as a whole. We call the whole an ice bar. If an icy bar (no matter how many squares does it contain) has two free ends, we call it a free ice bar. Free ice bars immediate drop down vertically when all its supporting squares (squares directly below it) are empty. When an icy square is cleared, all connections of it (if any) are destroyed. Because rocky squares are fixed, if an ice bar connects to one or two rocky squares, it never drops down until its connections to rocky squares are all destroyed. The '>' move is symmetrical. The 'L' move is a little bit complex, compared to what you might expect. Again, suppose the iceman is located at (r, c). If (r, c-1) is an empty square, the iceman go there. Now he stands on the square (r+1, c-1), which might be empty. If this is true, he falls down until the square under him is not empty. The iceman can launch a move only when he's standing on a rocky or icy square, so when falling down, he cannot do anything. Now consider the second case, i.e. (r, c-1) is rocky. Obviously the iceman cannot move to that square, so he checks the square above it and the square above himself (i.e the squares (r-1, c-1) and (r-1, c)). If both are empty, he climbs to (r-1, c-1), otherwise he remains at (r, c). The third and last case holds when (r, c-1) is icy. In this case, the iceman tries to push it. The Iceman is not so powerful, so he can only push single (1x1) icy squares. That is, if only if (r, c-2) is empty, the ice at (r, c-1) is pushed left. It continues to move left
until it is blocked by a rocky or icy square, or the square directly below is empty. In the latter case, the ice drops down, as stated before. Note that when stopped dropping, the ice does not move left again. Don't forget that when the ice is pushed away successfully, some free ice bars may drop down. The iceman does not move until everything stopped moving or dropping. If the ice at (r, c-1) cannot be pushed, it is treated as a rocky square, so the iceman may climb on it.Write a program to move the iceman to the destination with minimum number of moves.

Input
The input consists of several test cases. The first line of each case contains two integers, n and m (1 ≤ n, m ≤ 10). This is followed by n lines, each containing m characters. Each character is one of '.', 'X', '@', '#', 'O', '[', ']', '='. The last test case is followed by a single zero, which should not be processed.

Output
For each test case, print the case number and the move sequence. There is always a solution of at most 15 moves. It is guaranteed that the optimal solution is unique.

Sample Input
5 5
XXXXX
X@.#X
XX.XX
X...X
XXXXX
7 7
XXXXXXX
X.....X
X@[=].X
XXX.XXX
XXX.XXX
XXX#XXX
XXXXXXX
6 6
XXXXXX
X@...X
XXXX=X
X..O.X
X.#O.X
XXXXXX
0

Sample Output
Case 1: >RR
Case 2: R>R
Case 3: RR>RLLLLL>R

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序