编程介的小学生 2017-08-19 07:04 采纳率: 20.5%
浏览 843
已采纳

Left Library Lift

Left library lift
Every Friday midnight
Take to the floor eight
You will see the ghost

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条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥15 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败