zoj 2837 Left Library Lift

发布于 2020-02-11 23:34:20

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:&quot I took the left lift of the library to the 8th floor at Friday's midnight, but nothing happened.&quot

&quotReally?&quot his classmate replied, &quotIn 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.

&quotWell,&quot Dick asked, &quotaccording to your rules, on average, how many times should I roll the die to arrive at that floor?&quot

Input

The input consists of multiple test cases.

Every test case contains two integers N and M (1 &lt M &lt= N &lt 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

关注者
0
被浏览
543
1 个回答
  • 面试哥
    面试哥 2020-02-11
    为面试而生,有面试问题,就找面试哥。
    #include <cstdio>
    #include <iostream>
    #include <cstring>
    using namespace std;
    double g_ans[34][43]={{},{},{0,0,2.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,2.00,3.36,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,3.00,3.00,6.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,3.96,3.36,3.47,6.85,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,4.61,4.97,4.91,3.78,8.37,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,5.59,5.58,6.00,5.33,5.01,9.45,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,6.53,6.49,6.52,6.40,5.87,5.37,12.42,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,7.40,7.52,7.67,6.85,7.07,6.29,6.83,14.02,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,8.34,8.38,8.55,7.85,7.51,7.58,7.90,7.48,15.52,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,9.26,9.33,9.46,8.68,8.37,7.83,9.50,8.69,8.16,17.07,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,10.17,10.26,10.44,9.50,9.19,8.68,9.71,10.29,9.58,8.92,18.69,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,11.10,11.18,11.36,10.37,9.97,9.45,10.71,10.44,11.07,10.30,9.83,20.45,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,12.02,12.11,12.31,11.21,10.79,10.15,11.62,11.47,11.17,11.89,11.09,10.62,22.45,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,12.94,13.04,13.25,12.06,11.59,10.92,12.42,12.34,12.21,11.94,12.78,11.96,11.55,24.06,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,13.87,13.97,14.19,12.91,12.40,11.66,13.32,13.13,13.05,12.96,12.77,13.76,12.98,12.31,25.70,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,14.79,14.90,15.14,13.76,13.21,12.41,14.18,14.02,13.82,13.80,13.78,13.65,14.86,13.82,13.10,27.39,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,15.71,15.82,16.08,14.61,14.01,13.16,15.04,14.86,14.70,14.56,14.62,14.69,14.69,15.72,14.66,13.92,29.11,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,16.64,16.75,17.02,15.46,14.82,13.91,15.92,15.71,15.52,15.43,15.37,15.54,15.77,15.50,16.61,15.50,14.77,30.86,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,17.56,17.68,17.97,16.31,15.63,14.66,16.78,16.57,16.36,16.24,16.23,16.29,16.63,16.58,16.33,17.53,16.36,15.59,32.61,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,18.48,18.61,18.91,17.16,16.44,15.40,17.65,17.42,17.21,17.07,17.04,17.15,17.38,17.44,17.42,17.18,18.47,17.25,16.42,34.29,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,19.41,19.54,19.85,18.00,17.24,16.15,18.52,18.28,18.04,17.90,17.86,17.96,18.27,18.18,18.27,18.28,18.06,19.43,18.13,17.23,35.99,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,20.33,20.47,20.79,18.85,18.05,16.90,19.39,19.13,18.88,18.73,18.69,18.79,19.09,19.06,19.01,19.14,19.17,18.94,20.38,18.99,18.05,37.70,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,21.25,21.39,21.74,19.70,18.86,17.65,20.26,19.99,19.72,19.56,19.51,19.62,19.93,19.88,19.89,19.87,20.03,20.08,19.83,21.29,19.85,18.87,39.43,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,22.18,22.32,22.68,20.55,19.67,18.40,21.13,20.84,20.56,20.39,20.34,20.45,20.78,20.72,20.70,20.75,20.76,20.94,20.98,20.68,22.22,20.71,19.70,41.15,1000.00,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,23.10,23.25,23.62,21.40,20.48,19.15,22.00,21.70,21.40,21.22,21.16,21.28,21.61,21.56,21.54,21.56,21.64,21.66,21.84,21.85,21.54,23.16,21.58,20.52,42.86,1000.00,1000.00,1000.00,1000.00,1000.00},
    {0,0,24.02,24.18,24.57,22.25,21.29,19.90,22.87,22.55,22.24,22.05,21.99,22.10,22.45,22.39,22.37,22.39,22.45,22.55,22.56,22.71,22.72,22.41,24.09,22.45,21.34,44.57,1000.00,1000.00,1000.00,1000.00},
    {0,0,24.95,25.11,25.51,23.10,22.09,20.64,23.74,23.41,23.08,22.87,22.81,22.93,23.30,23.23,23.20,23.23,23.28,23.36,23.45,23.42,23.58,23.60,23.29,25.03,23.32,22.16,46.28,1000.00,1000.00,1000.00},
    {0,0,25.87,26.04,26.45,23.95,22.90,21.39,24.61,24.26,23.92,23.70,23.64,23.76,24.14,24.06,24.04,24.06,24.12,24.19,24.26,24.31,24.29,24.47,24.49,24.16,25.97,24.18,22.98,48.00,1000.00,1000.00},
    {0,0,26.79,26.96,27.40,24.80,23.71,22.14,25.48,25.11,24.76,24.53,24.46,24.58,24.98,24.90,24.87,24.89,24.95,25.03,25.10,25.12,25.18,25.17,25.36,25.38,25.03,26.90,25.05,23.81,49.72,1000.00},
    {0,0,27.71,27.89,28.34,25.65,24.52,22.89,26.35,25.97,25.60,25.36,25.29,25.41,25.82,25.73,25.70,25.72,25.78,25.86,25.94,25.95,25.99,26.07,26.05,26.24,26.26,25.89,27.83,25.92,24.63,51.43}
    };
    
    int main()
    {
     int n,m;
     while (cin>>n>>m)
     {
     printf("%0.2f\n",g_ans[n][m]);
     }
     return 0;
    }
推荐阅读
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看