something about my mistake.----p1475_push the boxes
来源:互联网 发布:手机led灯软件 编辑:程序博客网 时间:2024/05/10 05:51
Pushing Boxes
Time Limit: 2000MSMemory Limit: 131072KTotal Submissions: 1963Accepted: 754Special Judge
Description
Imagineyou are standing inside a two-dimensional maze composed of square cellswhich may or may not be filled with rock. You can move north, south,east or west one cell at a step. These moves are called walks.
One of the empty cells contains a box which can be moved to anadjacent free cell by standing next to the box and then moving in thedirection of the box. Such a move is called a push. The box cannot bemoved in any other way than by pushing, which means that if you push itinto a corner you can never get it out of the corner again.
One of the empty cells is marked as the target cell. Your job is tobring the box to the target cell by a sequence of walks and pushes. Asthe box is very heavy, you would like to minimize the number of pushes.Can you write a program that will work out the best such sequence?
One of the empty cells contains a box which can be moved to anadjacent free cell by standing next to the box and then moving in thedirection of the box. Such a move is called a push. The box cannot bemoved in any other way than by pushing, which means that if you push itinto a corner you can never get it out of the corner again.
One of the empty cells is marked as the target cell. Your job is tobring the box to the target cell by a sequence of walks and pushes. Asthe box is very heavy, you would like to minimize the number of pushes.Can you write a program that will work out the best such sequence?
Input
Theinput contains the descriptions of several mazes. Each maze descriptionstarts with a line containing two integers r and c (both <= 20)representing the number of rows and columns of the maze.
Following this are r lines each containing c characters. Eachcharacter describes one cell of the maze. A cell full of rock isindicated by a `#' and an empty cell is represented by a `.'. Yourstarting position is symbolized by `S', the starting position of thebox by `B' and the target cell by `T'.
Input is terminated by two zeroes for r and c.
Following this are r lines each containing c characters. Eachcharacter describes one cell of the maze. A cell full of rock isindicated by a `#' and an empty cell is represented by a `.'. Yourstarting position is symbolized by `S', the starting position of thebox by `B' and the target cell by `T'.
Input is terminated by two zeroes for r and c.
Output
Foreach maze in the input, first print the number of the maze, as shown inthe sample output. Then, if it is impossible to bring the box to thetarget cell, print ``Impossible.''.
Otherwise, output a sequence that minimizes the number of pushes.If there is more than one such sequence, choose the one that minimizesthe number of total moves (walks and pushes). If there is still morethan one such sequence, any one is acceptable.
Print the sequence as a string of the characters N, S, E, W, n, s,e and w where uppercase letters stand for pushes, lowercase lettersstand for walks and the different letters stand for the directionsnorth, south, east and west.
Output a single blank line after each test case.
Otherwise, output a sequence that minimizes the number of pushes.If there is more than one such sequence, choose the one that minimizesthe number of total moves (walks and pushes). If there is still morethan one such sequence, any one is acceptable.
Print the sequence as a string of the characters N, S, E, W, n, s,e and w where uppercase letters stand for pushes, lowercase lettersstand for walks and the different letters stand for the directionsnorth, south, east and west.
Output a single blank line after each test case.
Sample Input
1 7
SB....T
1 7
SB..#.T
7 11
###########
#T##......#
#.#.#..####
#....B....#
#.######..#
#.....S...#
###########
8 4
....
.##.
.#..
.#..
.#.B
.##S
....
###T
0 0
Sample Output
Maze #1
EEEEE
Maze #2
Impossible.
Maze #3
eennwwWWWWeeeeeesswwwwwwwnNN
Maze #4
swwwnnnnnneeesssSSS
Source
Southwestern European Regional Contest 1997
if one has the commen sense of dp or bfs.
he can tell me that this one is not a dp_tree problem.
because the relationship of one grid and its adjecent ones is not father_son relationship, instead, the are in disorder ,
so it can't be solved using dp_tree model.
but i am so foolish and forgetable that i used this method , wa! and debug it for many hours.
Miss Carrot , you should think more clearly before code.!
ok ! you know you can!
- something about my mistake.----p1475_push the boxes
- something about my intern interview
- something about consistency form my perspective
- Something about the HTK tool
- something about the systemverilog--- interface
- Something about the Sampling of OSNs Data
- something about set the FSDB file
- Something about the git cherry-pick
- Something about ...
- Could you tell something about the Unix System Kernel?
- [知其然不知其所以然-23] Something about the printk loglevel and var_list
- My plan about the winter holiday
- The annoying problem about my BIG TOE
- My idea about the organization about block buffer cache
- Something about float divide
- something about Tomcat(zz)
- something about Listeners
- something about Macro
- Ado.net2.0中的事务处理
- 自动聊天机器人
- js中这样获取textarea的值
- 【Android笔记】Activity不同状态间转换研究
- tcpl 阅读笔记 7
- something about my mistake.----p1475_push the boxes
- 2009-07-23 TIPTOP
- 师者,传道授业解惑者也:看现在的培训机构和毕业生就业状况
- MPICH2的安装
- Matlab中的pchiptx.m 修改为C语言 三次样条插值
- 程序员的出路在哪里?
- 第一个JPA程序
- 高斯消元求矩阵解
- as的xml遍历算法