码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 10047 - The Monocycle

时间:2014-07-06 11:49:47      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:uva   acm   graph   bfs   

题目如下:


 Problem A: The Monocycle 

A monocycle is a cycle that runs on one wheel and the one we will be considering is a bit more special. It has a solid wheel colored with five differentcolors as shown in the figure:

bubuko.com,布布扣

The colored segments make equal angles (72o) atthe center. A monocyclist rides this cycle on an bubuko.com,布布扣grid of squaretiles. The tiles have such size that moving forward from the center of onetile to that of the next one makes the wheel rotate exactly 72o around itsown center. The effect is shown in the above figure. When the wheel is at thecenter of square 1, the mid-point of the periphery of its blue segment is intouch with the ground. But when the wheel moves forward to the center of thenext square (square 2) the mid-point of its white segment touches the ground.

bubuko.com,布布扣

Some of the squares of the grid are blocked and hencethe cyclist cannot move to them. The cyclist starts from some square and triesto move to a target square in minimum amount of time. From any square eitherhe moves forward to the next square or he remains in the same square but turns90o left or right. Each of these actions requires exactly 1 second toexecute. He always starts his ride facing north and with the mid-point of thegreen segment of his wheel touching the ground. In the target square, too, thegreen segment must be touching the ground but he does not care about thedirection he will be facing.

Before he starts his ride, please help him find out whetherthe destination is reachable and if so the minimum amount of time he willrequire to reach it.

Input 

The input may contain multiple test cases.

The first line of each test case contains two integers M and N (bubuko.com,布布扣,bubuko.com,布布扣)giving the dimensions of the grid. Then follows the description ofthe grid in M lines of N characters each. The character `#‘ willindicate a blocked square, all other squares are free. The starting locationof the cyclist is marked by `S‘ and the target is marked by `T‘. The input terminates with two zeros for M and N.

Output 

For each test case in the input first print the test case number on aseparate line as shown in the sample output. If the target location can bereached by the cyclist print the minimum amount of time (in seconds) requiredto reach it exactly in the format shown in the sample output, otherwise, print``destination not reachable".

Print a blank line between two successive test cases.

Sample Input 

1 3
S#T
10 10
#S.......#
#..#.##.##
#.##.##.##
.#....##.#
##.##..#.#
#..#.##...
#......##.
..##.##...
#.###...#.
#.....###T
0 0

Sample Output 

Case #1
destination not reachable
 
Case #2
minimum time = 49 sec

求一个点到另一个点的最短时间,明显用BFS,但限制条件比较多,要求终点的颜色和起点相同,并且车轮有方向,只能前进或左转90°或右转90°,所以用四位数组来标记,代表坐标,颜色,方向,然后正常的模拟和BFS,模拟左转,右转,前进,根据方向的不同前进的坐标变化也有所不同,所以位移数组和方向要对应起来。

AC的代码如下:


UVA 10047 - The Monocycle,布布扣,bubuko.com

UVA 10047 - The Monocycle

标签:uva   acm   graph   bfs   

原文地址:http://blog.csdn.net/u013840081/article/details/36885121

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!