UVA 10047 - The Monocycle

题目如下:

 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:

The colored segments make equal angles (72o) atthe center. A monocyclist rides this cycle on an
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.

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 (,)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

时间: 2024-10-20 22:36:13

UVA 10047 - The Monocycle的相关文章

uva 10047 - The Monocycle bfs

题目链接 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 different colors as shown in the figure: The colored segments make equal angles (72o) at the center. A

UVA 10047 - The Monocycle(BFS)

题目链接:点击打开链接 题意:从起点到终点,每秒可以选择前进.向左.向右转, 每前进一格轮子转到下一个颜色, 一共5中颜色, 开始的时候绿色接触地面,朝北, 要求最后也绿色接触地面,求能否到达目标点以及最短时间. 思路:和普通BFS相比,多了两个附加条件,所以要将状态表示全面,也要对应加两维. 水题. 细节参见代码: #include<cstdio> #include<cstring> #include<algorithm> #include<iostream&g

UVA - 10047 The Monocycle (BFS)

题目大意:有一个n*m的网格,网格上面有的地方有障碍物 现在有一个人,骑着独轮车,要求从一个地方到达另一个地方,骑独轮车时,只能直走,或者左拐,右拐,不能向后走 独轮车的轮子被分成了5部分,每部分都有对应的颜色,刚开始时是绿色向下,当经过一个格子时,颜色就会变换 问从起点出发到终点,到终点时独轮车的绿色颜色向下,需要多久 解题思路:暴力BFS #include <cstdio> #include <cstring> #include <algorithm> #inclu

uva 10047 uva live 2035 The Monocycle bfs

// uva 10047 uva live 2035 bfs // 求最短的嘛,肯定先尝试bfs啦 // 确定状态,首先状态里面得有坐标x,y // 还得有朝向,还得有颜色值 // // 这样就是一个状态里面有着三种属性 // 每个状态都只要经历一次,再经历是没有任何意义的 // 用一个que的思维数组记录就行了. // 按照方向爆搜,我先用f[i][j]记录的就是到 // 这一点的最小距离,但是怎么都过不了样例 // 突然明白了,如果只是这样记录最短距离,是不行的 // 因为每次从队列中取出的

UVA 11624 UVA 10047 两道用 BFS进行最短路搜索的题

很少用bfs进行最短路搜索,实际BFS有时候挺方便得,省去了建图以及复杂度也降低了O(N*M): UVA 11624 写的比较挫 #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; struct node{ int ft; int sta; }flo[1010][1010]; int vis[1010][1010]; st

The Monocycle UVA 10047

说说: 这算是一道比较难的题目了,拖到今天终于搞定啦!题意是这样的,有如下这样一个棋盘:一个轮子从S出发开始运动,它有三个选择,沿原方向向前滚一格,或者在原地向左或向右转90度,并且无论是滚动还是转身都将耗时一秒.其中轮子由五种颜色组成,每滚动一个,与地面接触的颜色都将变换一次,如下图所示.假设开始的时候轮子停在S初,方向朝北,颜色为绿色,则能否到达目的地T,且颜色仍旧为绿色,求最短时间. 分析:开始的时候想法非常简单,就是DFS嘛,看能不能到达T,到时候再看看颜色的状态都差不多了.其实这是不对

The Monocycle,UVa 10047(状态记录广搜)

题目链接:http://acm.hust.edu.cn/vjudge/problem/36951 题意: 一辆独轮车,他的车轮每72度变一个颜色(蓝,白,绿,黑,红)..每秒有3种操作,左转,右转,或者前进,前进的时候车轮的颜色会向前进一色.要求出到终点且车轮触底颜色为蓝色的最小时间. 初始时间为轮子触底为蓝,朝向北 源代码: #include<iostream> #include<cstdio> #include<cstring> #include<queue&

UVa 10047 独轮车

题意:独轮车均分为5个部分即五种颜色,每次前进一格恰好换一种颜色接触地面.要求从起点走到终点,但是起点时人是面向北的.绿色接触地面,终点时需要绿色接触地面.朝向哪无所谓.其中,在每个格子,有三种选择,要么前进一格,要么左转90度,要么右转90度.每种选择都是耗时一秒. 思路:将每种约束都看做一个属性,或者说一个状态由4元组决定:横坐标.纵坐标.方向.颜色.这样起始状态知道.终点状态知道,进行bfs搜索即得到最短路径.在状态转化时,有相应的三种选择,前进对应于修改横纵坐标和颜色,左转右转对应于修改

UVa (BFS) The Monocycle

题目不光要求要到达终点而且要求所走的步数为5的倍数,每个时刻有三个选择,前进,左转弯,右转弯. 所以在vis数组中新增加两个维度即可,vis[x][y][dir][color]表示在(x, y)格子方向朝dir与地面接触的扇形的颜色为color,这个状态是否到达过. 1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 using namespace std; 5 6 const int maxn =