306738: CF1245E. Hyakugoku and Ladders

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Hyakugoku and Ladders

题意翻译

### 题意描述 给定一张10*10的地图,从坐标 $(10, 1)$ 出发,到达坐标 $(1, 1)$ ,规则如下: 首先说明向前走的路径(有关路径的可视化,请参阅样例解释): - 对于坐标 $(x, y)$ ,当 $x$ 是奇数,若 $y = 1$,则下一个点是 $(x - 1, 1)$,否则是 $(x, y - 1)$; - 当 $x$ 是偶数,若 $y = n$,则下一个点是 $(x - 1, n)$,否则是 $(x, y + 1)$. - $(1, 1)$ 是路径终点,没有下一个点。 每个回合掷一次骰子,掷出的点数**等概率**是 1,2,3,4,5,6,设掷出的点数是 x,如果存在当前前面有 x 个点,走到当前点前面 x 个点,否则不移动(**但也要算一回合**)。 若走到的点是一个梯子的**底部**,可以选择爬梯子到**顶部**(**也可以不爬**)。 注意: 1. 梯子可能有重复部分,但爬梯子时**不能从一个梯子切换到其他梯子上**。 2. 可能出现一个梯子顶部是另一个梯子底部的情况,但当从第一个梯子底部爬到这个梯子顶部后,**不能爬另一个梯子**。 求从起点到终点最小期望回合数。 ### 输入格式 10*10 的矩阵 $h_{i, j}$,若 $h_{i, j} = 0$,表示没有以 $(i, j)$ 为底的楼梯,否则表示有以 $(i, j)$ 为底、以 $(i - h_{i,j}, j)$ 为顶的梯子,保证 $1 \leq i - h_{i,j} \leq n$. ### 样例解释 样例二路径如图 ![](https://espresso.codeforces.com/7a2b1f3f378ccd7824b813e439de0f3a7a77ee0d.png)

题目描述

Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she wants to try a different game — "Snakes and Ladders". Unfortunately, she already killed all the snakes, so there are only ladders left now. The game is played on a $ 10 \times 10 $ board as follows: - At the beginning of the game, the player is at the bottom left square. - The objective of the game is for the player to reach the Goal (the top left square) by following the path and climbing vertical ladders. Once the player reaches the Goal, the game ends. - The path is as follows: if a square is not the end of its row, it leads to the square next to it along the direction of its row; if a square is the end of its row, it leads to the square above it. The direction of a row is determined as follows: the direction of the bottom row is to the right; the direction of any other row is opposite the direction of the row below it. See Notes section for visualization of path. - During each turn, the player rolls a standard six-sided dice. Suppose that the number shown on the dice is $ r $ . If the Goal is less than $ r $ squares away on the path, the player doesn't move (but the turn is performed). Otherwise, the player advances exactly $ r $ squares along the path and then stops. If the player stops on a square with the bottom of a ladder, the player chooses whether or not to climb up that ladder. If she chooses not to climb, then she stays in that square for the beginning of the next turn. - Some squares have a ladder in them. Ladders are only placed vertically — each one leads to the same square of some of the upper rows. In order for the player to climb up a ladder, after rolling the dice, she must stop at the square containing the bottom of the ladder. After using the ladder, the player will end up in the square containing the top of the ladder. She cannot leave the ladder in the middle of climbing. And if the square containing the top of the ladder also contains the bottom of another ladder, she is not allowed to use that second ladder. - The numbers on the faces of the dice are 1, 2, 3, 4, 5, and 6, with each number having the same probability of being shown. Please note that: - it is possible for ladders to overlap, but the player cannot switch to the other ladder while in the middle of climbing the first one; - it is possible for ladders to go straight to the top row, but not any higher; - it is possible for two ladders to lead to the same tile; - it is possible for a ladder to lead to a tile that also has a ladder, but the player will not be able to use that second ladder if she uses the first one; - the player can only climb up ladders, not climb down. Hyakugoku wants to finish the game as soon as possible. Thus, on each turn she chooses whether to climb the ladder or not optimally. Help her to determine the minimum expected number of turns the game will take.

输入输出格式

输入格式


Input will consist of ten lines. The $ i $ -th line will contain 10 non-negative integers $ h_{i1}, h_{i2}, \dots, h_{i10} $ . If $ h_{ij} $ is $ 0 $ , then the tile at the $ i $ -th row and $ j $ -th column has no ladder. Otherwise, the ladder at that tile will have a height of $ h_{ij} $ , i.e. climbing it will lead to the tile $ h_{ij} $ rows directly above. It is guaranteed that $ 0 \leq h_{ij} < i $ . Also, the first number of the first line and the first number of the last line always contain $ 0 $ , i.e. the Goal and the starting tile never have ladders.

输出格式


Print only one line containing a single floating-point number — the minimum expected number of turns Hyakugoku can take to finish the game. Your answer will be considered correct if its absolute or relative error does not exceed $ 10^{-6} $ .

输入输出样例

输入样例 #1

0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

输出样例 #1

33.0476190476

输入样例 #2

0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 3 0 0 0 4 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 4 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 4 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9

输出样例 #2

20.2591405923

输入样例 #3

0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 6 6 6 6 6 6 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

输出样例 #3

15.9047592939

说明

A visualization of the path and the board from example 2 is as follows: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1245E/43b532b250e8898c1ca20662157f9e4153d49da7.png) The tile with an 'S' is the starting tile and the tile with an 'E' is the Goal. For the first example, there are no ladders. For the second example, the board looks like the one in the right part of the image (the ladders have been colored for clarity). It is possible for ladders to overlap, as is the case with the red and yellow ladders and green and blue ladders. It is also possible for ladders to go straight to the top, as is the case with the black and blue ladders. However, it is not possible for ladders to go any higher (outside of the board). It is also possible that two ladders lead to the same tile, as is the case with the red and yellow ladders. Also, notice that the red and yellow ladders lead to the tile with the orange ladder. So if the player chooses to climb either of the red and yellow ladders, they will not be able to climb the orange ladder. Finally, notice that the green ladder passes through the starting tile of the blue ladder. The player cannot transfer from the green ladder to the blue ladder while in the middle of climbing the green ladder.

Input

题意翻译

### 题意描述 给定一张10*10的地图,从坐标 $(10, 1)$ 出发,到达坐标 $(1, 1)$ ,规则如下: 首先说明向前走的路径(有关路径的可视化,请参阅样例解释): - 对于坐标 $(x, y)$ ,当 $x$ 是奇数,若 $y = 1$,则下一个点是 $(x - 1, 1)$,否则是 $(x, y - 1)$; - 当 $x$ 是偶数,若 $y = n$,则下一个点是 $(x - 1, n)$,否则是 $(x, y + 1)$. - $(1, 1)$ 是路径终点,没有下一个点。 每个回合掷一次骰子,掷出的点数**等概率**是 1,2,3,4,5,6,设掷出的点数是 x,如果存在当前前面有 x 个点,走到当前点前面 x 个点,否则不移动(**但也要算一回合**)。 若走到的点是一个梯子的**底部**,可以选择爬梯子到**顶部**(**也可以不爬**)。 注意: 1. 梯子可能有重复部分,但爬梯子时**不能从一个梯子切换到其他梯子上**。 2. 可能出现一个梯子顶部是另一个梯子底部的情况,但当从第一个梯子底部爬到这个梯子顶部后,**不能爬另一个梯子**。 求从起点到终点最小期望回合数。 ### 输入格式 10*10 的矩阵 $h_{i, j}$,若 $h_{i, j} = 0$,表示没有以 $(i, j)$ 为底的楼梯,否则表示有以 $(i, j)$ 为底、以 $(i - h_{i,j}, j)$ 为顶的梯子,保证 $1 \leq i - h_{i,j} \leq n$. ### 样例解释 样例二路径如图 ![](https://espresso.codeforces.com/7a2b1f3f378ccd7824b813e439de0f3a7a77ee0d.png)

加入题单

上一题 下一题 算法标签: