something about my mistake.----p1475_push the boxes
2009-09-09 19:19
232 查看
Pushing Boxes
Description
Imagine
you are standing inside a two-dimensional maze composed of square cells
which 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 an
adjacent free cell by standing next to the box and then moving in the
direction of the box. Such a move is called a push. The box cannot be
moved in any other way than by pushing, which means that if you push it
into 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 to
bring the box to the target cell by a sequence of walks and pushes. As
the 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?
![](http://acm.pku.edu.cn/JudgeOnline/images/1475_1.jpg)
Input
The
input contains the descriptions of several mazes. Each maze description
starts 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. Each
character describes one cell of the maze. A cell full of rock is
indicated by a `#' and an empty cell is represented by a `.'. Your
starting position is symbolized by `S', the starting position of the
box by `B' and the target cell by `T'.
Input is terminated by two zeroes for r and c.
Output
For
each maze in the input, first print the number of the maze, as shown in
the sample output. Then, if it is impossible to bring the box to the
target 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 minimizes
the number of total moves (walks and pushes). If there is still more
than 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 letters
stand for walks and the different letters stand for the directions
north, south, east and west.
Output a single blank line after each test case.
Sample Input
Sample Output
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!
Time Limit: 2000MS | Memory Limit: 131072K | |||
Total Submissions: 1963 | Accepted: 754 | Special Judge |
Imagine
you are standing inside a two-dimensional maze composed of square cells
which 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 an
adjacent free cell by standing next to the box and then moving in the
direction of the box. Such a move is called a push. The box cannot be
moved in any other way than by pushing, which means that if you push it
into 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 to
bring the box to the target cell by a sequence of walks and pushes. As
the 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?
![](http://acm.pku.edu.cn/JudgeOnline/images/1475_1.jpg)
Input
The
input contains the descriptions of several mazes. Each maze description
starts 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. Each
character describes one cell of the maze. A cell full of rock is
indicated by a `#' and an empty cell is represented by a `.'. Your
starting position is symbolized by `S', the starting position of the
box by `B' and the target cell by `T'.
Input is terminated by two zeroes for r and c.
Output
For
each maze in the input, first print the number of the maze, as shown in
the sample output. Then, if it is impossible to bring the box to the
target 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 minimizes
the number of total moves (walks and pushes). If there is still more
than 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 letters
stand for walks and the different letters stand for the directions
north, 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 consistency form my perspective
- The annoying problem about my BIG TOE
- Something about the Sampling of OSNs Data
- [知其然不知其所以然-23] Something about the printk loglevel and var_list
- Something about the linux/Documentation/kbuild
- something about the systemverilog--- interface
- Something about the microsoft HttpContext domain design
- Could you tell something about the Unix System Kernel?
- My idea about the organization about block buffer cache
- something about the SV_POSITION
- Diesel engine looks after shop for just about every individual member of my family because of the deals
- the unpack error when I push my modification to the Gerrit
- The world won't care about your self-esteem. The world will expect you to accomplish something before you feel good about yourself.
- Something about the HTK tool
- something about set the FSDB file
- Something About USB On-The-Go
- Something about the git cherry-pick
- Something about the Inter Prediction of HEVC Based on HM9.0
- The annoying problem about my BIG TOE
- HDU 1492 The number of divisors(约数) about Humble Numbers