#P8213. [THUPC 2022 初赛] 挑战
[THUPC 2022 初赛] 挑战
Problem Description
Alice and Bob, who are smart enough, are playing a board game. The game uses a long board with cells. Number the cells from left to right as . Except for the cell numbered , each cell has two numbers . Before the game starts, place a piece on cell . The two players take turns to operate; assume Alice moves first.
When it is a player's turn, the player can decide how many steps to move forward based on the current cell's value. Specifically, suppose the piece is currently on cell . Then the current player may move the piece forward by cells, where can be any integer satisfying . If the player does not move the full cells, i.e. , then after the move the player may choose whether to start a challenge. If they choose not to challenge, then the other player takes the next turn. Otherwise, if the current player chooses to challenge, the system generates two random integers and , where:
- is the energy of the challenge. It is generated uniformly at random in .
- is the activation energy required for the challenge. It is generated uniformly at random in .
Based on the values of and , the system determines the outcome automatically using the following rules:
- If , the challenge succeeds. The other player's next turn is skipped, and the current player continues to operate.
- If , the challenge is a draw. Nothing happens, and the other player operates next.
- If , the challenge fails. The current player's next turn will be skipped, i.e. the other player can operate for two consecutive turns.
To prevent one player from being skipped forever, the following rules apply:
- If the current player gains an extra operation opportunity through their own challenge, then in that extra opportunity they cannot start a second challenge.
- If the current player gains an extra operation opportunity through the other player's challenge, then they cannot start a challenge at the end of their first operation. They may only choose whether to challenge at the end of their second operation, and they can make a third operation if and only if the challenge succeeds.
Note that no matter how many consecutive operations occur, in each operation the piece must be moved forward by at least cell. As in most games, whoever moves the piece to the terminal cell (the cell numbered ) wins.
Both Alice and Bob are smart enough to compute mentally, for the current position of the piece, the operation that maximizes their probability of winning. As an observer, you are not as good at mental calculation as they are; however, you want to use programming to compute Alice's winning probability when Alice moves first starting from cell .
Input Format
The first line contains a positive integer , indicating that the board has cells, numbered .
The second line contains positive integers , representing the values of cells to .
The third line contains positive integers , representing the values of cells to .
Output Format
Output a real number representing Alice's winning probability when Alice moves first. Your output is considered correct if its absolute error compared with the standard output does not exceed .
3
3 3 3
1 2 3
1.000000000000000000
3
2 3 3
1 2 3
0.250000000000000000
10
2 1 4 7 4 8 3 6 4 8
3 1 4 1 5 9 2 6 5 3
0.833333333333333333
Hint
[Sample Explanation 1]
Alice moves first. Since she can move directly from cell to the terminal cell , Alice will move the piece directly to cell , so Alice will surely win.
[Sample Explanation 2]
Alice moves first, but she cannot move directly to cell . Also, no matter whether the piece ends the operation on cell or cell , Bob can move it directly to the terminal cell . Therefore, Alice must attempt a challenge. If she moves the piece to cell and starts a challenge, the probability that the challenge succeeds is , so Alice's winning probability is .
[Constraints]
For of the testdata, it is guaranteed that and .
Translated by ChatGPT 5