CF24D.Broken robot

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of N rows and M columns of cells. The robot is initially at some cell on the i-th row and the j-th column. Then at every step the robot could go to some another cell. The aim is to go to the bottommost (N-th) row. The robot can stay at it's current cell, move to the left, move to the right, or move to the cell below the current. If the robot is in the leftmost column it cannot move to the left, and if it is in the rightmost column it cannot move to the right. At every step all possible moves are equally probable. Return the expected number of step to reach the bottommost row.

你收到了一个非常聪明的机器人作为礼物,它在一个矩形棋盘上行走。不幸的是,你发现它坏了,行为表现得相当异常(即随机)。该棋盘由 NN 行和 MM 列单元格组成。机器人初始时位于第 ii 行、第 jj 列的某个单元格上。随后,在每一步中,机器人可以移动到另一个单元格。目标是到达最底行(即第 NN 行)。机器人在每一步中可选择:停留在当前单元格、向左移动、向右移动,或向下移动至当前单元格正下方的单元格。若机器人位于最左列,则不能向左移动;若位于最右列,则不能向右移动。在每一步中,所有可行的移动方式出现的概率均相等。请返回机器人到达最底行所需的期望步数。

输入格式

On the first line you will be given two space separated integers N and M (1 ≤ N, M ≤ 1000). On the second line you will be given another two space separated integers i and j (1 ≤ i ≤ N, 1 ≤ j ≤ M) — the number of the initial row and the number of the initial column. Note that, (1, 1) is the upper left corner of the board and (N, M) is the bottom right corner.

第一行将给出两个以空格分隔的整数 NN 和 MM(1≤N,M≤10001 \leq N, M \leq 1000)。
第二行将给出另外两个以空格分隔的整数 ii 和 jj(1≤i≤N1 \leq i \leq N,1≤j≤M1 \leq j \leq M)——分别为初始行号和初始列号。注意,(1,1)(1, 1) 是棋盘的左上角,(N,M)(N, M) 是棋盘的右下角。

输出格式

Output the expected number of steps on a line of itself with at least 4 digits after the decimal point.

输出期望步数,结果保留至少小数点后 4 位。

输入输出样例

  • 输入#1

    10 10
    10 4

    输出#1

    0.0000000000
  • 输入#2

    10 14
    5 14

    输出#2

    18.0038068653

输入解题思路,AI测评打分。不知道怎么写?

首页