编程介的小学生 2017-09-02 08:39 采纳率: 20.5%
浏览 820
已采纳

Left Library Lift

It is said that the left lift of our library is a very dangerous place. There are many horrific ghost stories about it. Most students prefer to queue up by the right lift of the library, rather than to take the empty left one.

However, a brave student named Dick didn't believe in this.

He said:" I took the left lift of the library to the 8th floor at Friday's midnight, but nothing happened."

"Really?" his classmate replied, "In fact the poem doesn't show the correct way to approach the ghost. To know the secret, you should take the left lift from the 1st floor (ground floor) with a die. Every time you roll the die to get a number from 1 to 6 randomly, and then you should take the same number of lift-floors upwards. If you arrive at the highest floor or the ground floor, you should reverse the direction.

For example, originally you are on the 1st floor. You roll the die and get a number 6, then you should take lift to the 7th (= 1 + 6) floor. Then you roll the die again and get a number 5, but the highest floor of the library is the 11th floor, so you should take 4 floors up to the 11th floor and then take 1 floor down to the 10th floor. Since now you get the down direction, and if next time you get a number 2, you should take 2 floors down, which makes you reach the 8th floor. Well, when you get there in this way, the ghost will come up.

"Well," Dick asked, "according to your rules, on average, how many times should I roll the die to arrive at that floor?"

Input

The input consists of multiple test cases.

Every test case contains two integers N and M (1 < M <= N < 32) in a single line. N is the number of floor while M is the floor where ghost appears.

Output

For each test case, output one real number - the average times Dick should roll the die to arrive the destination. Accurate the result up to 2 decimal digits.

Sample Input

11 8
Sample Output

9.50

  • 写回答

1条回答

  • threenewbee 2017-09-16 16:26
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀