#abc296e. E - Transition Game
E - Transition Game
Score : points
问题描述
给定一个包含 个数的序列:。其中,每个 ()满足 。
高桥和青木将进行 轮游戏。对于每一轮 ,第 轮游戏按以下方式进行:
- 青木指定一个正整数 。
- 在得知青木指定的 后,高桥从 到 (包括两端点)选择一个整数 ,并将其写在黑板上。
- 重复以下操作 次:
- 将黑板上所写的整数 替换为 。
若经过 次迭代后,黑板上出现数字 ,则高桥赢得第 轮;否则,青木赢得第 轮。
这里,对于每一轮 , 和 可以独立选择。
假设两位玩家都采取最优策略以求获胜,请找出高桥赢得的轮数。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a sequence of numbers: . Here, each satisfies .
Takahashi and Aoki will play rounds of a game. For each , the -th game will be played as follows.
-
Aoki specifies a positive integer .
-
After knowing Aoki has specified, Takahashi chooses an integer between and , inclusive, and writes it on a blackboard.
-
Repeat the following times.
- Replace the integer written on the blackboard with .
If is written on the blackboard after the iterations, Takahashi wins the -th round; otherwise, Aoki wins.
Here, and can be chosen independently for each .
Find the number of rounds Takahashi wins if both players play optimally to win.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Find the number of rounds Takahashi wins if both players play optimally to win.
Sample Input 1
3
2 2 3
Sample Output 1
2
In the first round, if Aoki specifies , Takahashi cannot win whichever option he chooses for : , , or .
For example, if Takahashi writes on the initial blackboard, the two operations will change this number as follows: , . The final number on the blackboard will be , so Aoki wins.
On the other hand, in the second and third rounds, Takahashi can win by writing and , respectively, on the initial blackboard, whatever value Aoki specifies as .
Therefore, if both players play optimally to win, Takashi wins two rounds: the second and the third. Thus, you should print .
Sample Input 2
2
2 1
Sample Output 2
2
In the first round, Takahashi can win by writing on the initial blackboard if specified by Aoki is odd, and if it is even.
Similarly, there is a way for Takahashi to win the second round. Thus, Takahashi can win both rounds: the answer is .
update @ 2024/3/10 12:18:32