当前位置:首页|资讯

GFG29 Snake and Ladder Problem

作者:您是打尖儿还是住店呢发布时间:2024-10-03

Given a 5x6 snakes and ladders board,  nd the minimum number of dice throws required to reach the destination or last cell (30 cell) from the source (1st cell).


You are given an integer N denoting the total number of snakes and ladders and an array arr[] of 2*N size where 2*i and (2*i + 1) values denote the starting and ending point respectively of i snake or ladder. The board looks like the following.


Example 1:


Input:

N = 8

arr[] = {3, 22, 5, 8, 11, 26, 20, 29, 

 17, 4, 19, 7, 27, 1, 21, 9}



Output: 3

Explanation:

The given board is the board shown in the  gure. For the above board 

output will be 3. 

a) For 1st throw get a 2. 

b) For 2nd throw get a 6.

c) For 3rd throw get a 2.

-----------

WA了好几次,没看清楚题目意思,初始是站在1的位置的,不是0的位置,所以入队列的时候是2-7的位置,不是1-6,一直没找到原因。。。



Copyright © 2024 aigcdaily.cn  北京智识时代科技有限公司  版权所有  京ICP备2023006237号-1