HDU3355Hop — Don’t Walk!题解BFS搜索
来源:互联网 发布:看电视的软件 编辑:程序博客网 时间:2024/04/29 01:38
Hop — Don’t Walk!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 766 Accepted Submission(s): 226
Problem DescriptionKERMIT THE FROG is a classic video game with a simple control and objective but requires a good deal of thinking.
You control an animated frog that can walk and hop, in both forward and backward directions. The frog stands in a space between an otherwise a contiguous line of tiles. Each tile is painted black on one side, and white on the other. The frog can walk (forward, or backward) over an adjacent tile (in front or behind him.)
When the frog walks over a tile, the tile slides to the space where the frog was standing. For example, in the adjacent figure, the frog has two tiles behind him, and three in front. We’ll use the notation BWFBBW to refer to this situation where F refers to the space (where the frog is standing,) B is a tile with its black face showing, while W is a tile with its white face showing. The forward direction is from left to right. If the frog were to walk forward, the resulting situation is BWBFBW. Similar behavior when the frog walks backward, the tile behind the frog slides to where the frog was standing. The frog can also hop over the tiles. The frog can hop over an adjacent tile landing on the tile next to it. For example, if the frog was to hop backward, it would land on the first (left-most) tile, and the tile would jump to the space where the frog was standing. In addition, the tile would flip sides. For example, hopping backward in the figure would result in the situation: FWWBBW. We challenge you to write a program to determine the minimum number of moves (walks or hops) to transform one tile configuration into another.
InputYour program will be tested on one or more test cases. Each test case is specified on a single line that specifies string S representing the initial tile arrangement. S is a non-empty string and no longer than 100 characters and is made of the letters ’B’, ’W’, and exactly one ’F’. The last line of the input file has one or more ’-’ (minus) characters.
OutputFor each test case, print the following line:
k. M
Where k is the test case number (starting at one,) and M is the minimum number of moves needed to transform the given arrangement to an arrangement that has no white tile(s) between any of its black tiles . The frog can be anywhere. M is -1 if the problem cannot be solved in less than 10 moves.
Note: There is a blank space before M.
Sample InputWWBBFBWWWFBWBWFWBBWBW---
Sample Output1. 02. 13. 2
Source2009 ANARC
RecommendlcyBFS很久才弄懂题意,走和跳是不同的。刚开始把p定义成全局变量,BFS内把ct.p写成p导致一直错误,和别人的的代码对比才发现。再次犯错。。。代码:
You control an animated frog that can walk and hop, in both forward and backward directions. The frog stands in a space between an otherwise a contiguous line of tiles. Each tile is painted black on one side, and white on the other. The frog can walk (forward, or backward) over an adjacent tile (in front or behind him.)
When the frog walks over a tile, the tile slides to the space where the frog was standing. For example, in the adjacent figure, the frog has two tiles behind him, and three in front. We’ll use the notation BWFBBW to refer to this situation where F refers to the space (where the frog is standing,) B is a tile with its black face showing, while W is a tile with its white face showing. The forward direction is from left to right. If the frog were to walk forward, the resulting situation is BWBFBW. Similar behavior when the frog walks backward, the tile behind the frog slides to where the frog was standing. The frog can also hop over the tiles. The frog can hop over an adjacent tile landing on the tile next to it. For example, if the frog was to hop backward, it would land on the first (left-most) tile, and the tile would jump to the space where the frog was standing. In addition, the tile would flip sides. For example, hopping backward in the figure would result in the situation: FWWBBW. We challenge you to write a program to determine the minimum number of moves (walks or hops) to transform one tile configuration into another.
k. M
Where k is the test case number (starting at one,) and M is the minimum number of moves needed to transform the given arrangement to an arrangement that has no white tile(s) between any of its black tiles . The frog can be anywhere. M is -1 if the problem cannot be solved in less than 10 moves.
Note: There is a blank space before M.
WWBBFBWWWFBWBWFWBBWBW---
1. 02. 13. 2
- HDU3355Hop — Don’t Walk!题解BFS搜索
- HDU 3355 Hop — Don’t Walk!
- POJ 3995 Hop — Don’t Walk! 已被翻译
- Timus 1104. Don’t Ask Woman about Her Age题解
- ZOJ Walk Through the Forest (dijkstra + BFS || 记忆化搜索)
- 639 - Don't Get Rooked(搜索回溯)
- 专题 简单搜索(bfs+dfs) 个人题解
- Uva 639—Don't Get Rooked
- HDU 4444 Walk (离散化建图+BFS+记忆化搜索) 绝对经典
- HDU 5335 Walk Out(Bfs搜索字典序最小的最短路)
- hdu 1142 A Walk Through the Forest bfs+记忆化搜索
- hrbust 1525 水神【纪念搜索题解100篇】【Bfs】
- Don't Cry
- Don't use XP!
- Don't Use Select *
- Don't you worry
- 三Don't原则
- Don't Wanna Try
- SerialPort同步和异步数据读取
- SerialPort同步和异步数据读取(二)(
- 网络共享故障(win2003)
- fedora下所要用到的命令集合
- java applet 问题相关
- HDU3355Hop — Don’t Walk!题解BFS搜索
- IT名流BLOG精选
- Global.asax 监控 Session
- 详解计算机主机网关的作用!---很有意思
- layout
- 单机搭建WinCE开发环境 -如何在CE6.0 image中加入MFC的支持, 及如何导出相关的SDK
- 职场经典语录
- 领导等于做人
- RPM -qa | grep httpd