21363_ChutterandLadder

2022-5-16 18:19| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505196910300-Problem List-采集的数据-后羿采集器.html

Pro.ID

21363

Title

Chutter and Ladder

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21363

AC

0

Submit

2

Ratio

0.00%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Here is a simpler version of the interesting game "Chutter and Ladder":

    Given a sequence of small grids, numbered from 0 to n-1. As the player of this game, your starting position is grid 0, and your destination is grid n-1. Each time you can drop a dice and move 1-6 steps forward according to the number on top of the dice. As the dice is perfect, each number from 1 to 6 can evenly show on top of the dice.

    However, each grid i is marked with an integer a[i], that means if you move into that grid, then you will immediately jump |a[i]| grids more ( if a[i] > 0, the direction is forward, otherwise it's backward ). For example, suppose grid 5 is marked with integer 3, -3 respectively, then when you come to grid 5, you will immediately move to grid 8 or 2 correspondingly. Of course, if a[i] is 0, then you will stay at grid i. It's guaranteed that you will always jump into a grid marked with 0.

    What's worse, the sequence is cyclic, that means when you are moving to a grid k which is out of the range of 0 and n-1, you will actually move to grid k%n.

    Now, given the configuration of the grids, please write a program to calculate the expected number of moves to reach grid n-1.

    输入

    Input may contain several test cases. The first lines is a positive integer T, ( 1 ≤ T ≤ 20 ), the number of test cases below. Each test cases starts with a positive integer n, ( 1 ≤ n ≤ 100 ), the number of grids in the game, followed by n integers a[i] ( -na[i] ≤ n ,  1 ≤ in ). It's guaranteed that grid 0 and grid n-1 is always marked with 0.

    输出

    Description

    Here is a simpler version of the interesting game "Chutter and Ladder":

    Given a sequence of small grids, numbered from 0 to n-1. As the player of this game, your starting position is grid 0, and your destination is grid n-1. Each time you can drop a dice and move 1-6 steps forward according to the number on top of the dice. As the dice is perfect, each number from 1 to 6 can evenly show on top of the dice.

    However, each grid i is marked with an integer a[i], that means if you move into that grid, then you will immediately jump |a[i]| grids more ( if a[i] > 0, the direction is forward, otherwise it's backward ). For example, suppose grid 5 is marked with integer 3, -3 respectively, then when you come to grid 5, you will immediately move to grid 8 or 2 correspondingly. Of course, if a[i] is 0, then you will stay at grid i. It's guaranteed that you will always jump into a grid marked with 0.

    What's worse, the sequence is cyclic, that means when you are moving to a grid k which is out of the range of 0 and n-1, you will actually move to grid k%n.

    Now, given the configuration of the grids, please write a program to calculate the expected number of moves to reach grid n-1.

    Input

    Input may contain several test cases. The first lines is a positive integer T, ( 1 ≤ T ≤ 20 ), the number of test cases below. Each test cases starts with a positive integer n, ( 1 ≤ n ≤ 100 ), the number of grids in the game, followed by n integers a[i] ( -na[i] ≤ n ,  1 ≤ in ). It's guaranteed that grid 0 and grid n-1 is always marked with 0.

    Output

    For each test case, please output the expected number of moves to reach grid n-1, round to 3 digits after the decimal point. If it's impossible to reach grid n-1, simply output "-1".

    Sample Input

    2
    3
    0 0 0
    8
    0 -1 -2 -3 -4 -5 -6 0

    Sample Output

    3.000
    -1

    Source

    样例输入

    2
    3
    0 0 0
    8
    0 -1 -2 -3 -4 -5 -6 0

    样例输出

    3.000
    -1

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部