310475: CF1839E. Decreasing Game
Description
This is an interactive problem.
Consider the following game for two players:
- Initially, an array of integers $a_1, a_2, \ldots, a_n$ of length $n$ is written on blackboard.
- Game consists of rounds. On each round, the following happens:
- The first player selects any $i$ such that $a_i \gt 0$. If there is no such $i$, the first player loses the game (the second player wins) and game ends.
- The second player selects any $j \neq i$ such that $a_j \gt 0$. If there is no such $j$, the second player loses the game (the first player wins) and game ends.
- Let $d = \min(a_i, a_j)$. The values of $a_i$ and $a_j$ are simultaneously decreased by $d$ and the next round starts.
It can be shown that game always ends after the finite number of rounds.
You have to select which player you will play for (first or second) and win the game.
InputThe first line contains a single integer $n$ ($1 \le n \le 300$) — the length of array $a$.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 300$) — array $a$.
InteractionInteraction begins after reading $n$ and array $a$.
You should start interaction by printing a single line, containing either "First" or "Second", representing the player you select.
On each round, the following happens:
- If you are playing as the first player, you should print a single integer $i$ ($1 \le i \le n$) on a separate line. After that, you should read a single integer $j$ ($-1 \le j \le n$) written on a separate line.
If $j = -1$, then you made an incorrect move. In this case your program should terminate immediately.
If $j = 0$, then the second player can't make a correct move and you win the game. In this case your program should also terminate immediately.
Otherwise $j$ is equal to the index chosen by the second player, and you should proceed to the next round.
- If you are playing as the second player, you should read a single integer $i$ ($-1 \le i \le n$) written on a separate line.
If $i = -1$, then you made an incorrect move on the previous round (this cannot happen on the first round). In that case your program should terminate immediately.
If $i = 0$, then the first player can't make a correct move and you win the game. In this case your program should also terminate immediately.
Otherwise $i$ is equal to the index chosen by first player. In this case you should write single integer $j$ ($1 \le j \le n$) on a separate line and proceed to the next round.
After printing $i$ or $j$, do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see the documentation for other languages.
Hacks
Hacks are disabled in this problem.
ExamplesInput4 10 4 6 3 3 1 0Output
First 1 2 4Input
6 4 5 5 11 3 2 2 5 4 6 1 0Output
Second 4 4 3 1 3Note
In the first example $n = 4$ and array $a$ is $[\, 10, 4, 6, 3 \,]$. The game goes as follows:
- After reading array $a$ contestant's program chooses to play as the first player and prints "First".
- First round: the first player chooses $i = 1$, the second player chooses $j = 3$. $d = \min(a_1, a_3) = \min(10, 6) = 6$ is calculated. Elements $a_1$ and $a_3$ are decreased by $6$. Array $a$ becomes equal to $[\, 4, 4, 0, 3 \,]$.
- Second round: the first player chooses $i = 2$, the second player chooses $j = 1$. $d = \min(a_2, a_1) = \min(4, 4) = 4$ is calculated. Elements $a_2$ and $a_1$ are decreased by $4$. Array $a$ becomes equal to $[\, 0, 0, 0, 3 \,]$.
- Third round: the first player chooses $i = 4$. There is no $j \neq 4$ such that $a_j > 0$, so the second player can't make a correct move and the first player wins. Jury's program prints $j = 0$. After reading it, contestant's program terminates.
In the second example $n = 6$ and array $a$ is $[\, 4, 5, 5, 11, 3, 2 \,]$. The game goes as follows:
- Contestant's program chooses to play as the second player and prints "Second".
- First round: $i = 2$, $j = 4$, $a = [\, 4, 0, 5, 6, 3, 2 \,]$.
- Second round: $i = 5$, $j = 4$, $a = [\, 4, 0, 5, 3, 0, 2 \,]$.
- Third round: $i = 4$, $j = 3$, $a = [\, 4, 0, 2, 0, 0, 2 \,]$.
- Fourth round: $i = 6$, $j = 1$, $a = [\, 2, 0, 2, 0, 0, 0 \,]$.
- Fifth round: $i = 1$, $j = 3$, $a = [\, 0, 0, 0, 0, 0, 0 \,]$.
- Sixth round: the first player can't make a correct move and the second player wins. Jury's program prints $i = 0$. After reading it, contestant's program terminates.
Note that the example interaction contains extra empty lines so that it's easier to read. The real interaction doesn't contain any empty lines and you shouldn't print any extra empty lines as well.
Input
题意翻译
这是一道交互题。 考虑如下的一个二人游戏: - 初始有一个长度为 $n$ 的数组 $ a_1, a_2, \ldots, a_n $。 - 游戏分若干轮进行,每轮会有如下操作: - 先手要选择一个 $ i $ 满足 $ a_i \gt 0 $,如果不存在这样的 $i$ 则后手获胜,游戏结束。 - 接着后手要选择一个 $j\neq i$ 满足 $ a_j \gt 0 $,如果不存在这样的 $j$ 则先手获胜,游戏结束。 - 令 $d=\min(a_i,a_j)$。$a_i,a_j$ 的值均会减少 $d$,本轮结束,下一轮开始。 显然游戏将会在有限轮内结束。给定数组 $a$,你需要选择先后手并赢得这场游戏。Output
1. 有一个长度为n的整数数组a。
2. 游戏由多轮组成,每轮如下进行:
- 第一名玩家选择一个大于0的a[i]。如果没有这样的i,则第一名玩家输,游戏结束。
- 第二名玩家选择一个不等于i且大于0的a[j]。如果没有这样的j,则第二名玩家输,游戏结束。
- 设d=min(a[i],a[j]),将a[i]和a[j]同时减少d,然后进行下一轮。
3. 游戏在有限轮后一定会结束。
你需要选择扮演哪一名玩家(第一名或第二名),并赢得游戏。
输入输出数据格式:
输入:
- 第一行包含一个整数n(1≤n≤300),表示数组a的长度。
- 第二行包含n个整数a[1],a[2],...,a[n](1≤a[i]≤300),表示数组a。
输出:
- 第一行输出一个字符串,"First"或"Second",表示你选择的玩家。
- 之后的每一行,根据你选择的玩家,输出相应的i或j。
交互过程:
- 如果你扮演第一名玩家,你需要在每一轮开始时输出一个整数i(1≤i≤n),然后读取一个整数j(-1≤j≤n)。
- 如果j=-1,则你做出了错误的移动。此时你的程序应立即终止。
- 如果j=0,则第二名玩家无法做出正确的移动,你赢得游戏。此时你的程序也应立即终止。
- 否则,j是第二名玩家选择的下标,你应继续进行下一轮。
- 如果你扮演第二名玩家,你需要在每一轮开始时读取一个整数i(-1≤i≤n)。
- 如果i=-1,则你在上一轮做出了错误的移动(这不会发生在第一轮)。此时你的程序应立即终止。
- 如果i=0,则第一名玩家无法做出正确的移动,你赢得游戏。此时你的程序也应立即终止。
- 否则,i是第一名玩家选择的下标。此时你应输出一个整数j(1≤j≤n),然后继续进行下一轮。
注意:在输出i或j后,不要忘记输出换行符,并刷新输出缓冲区,否则你将得到“Idleness limit exceeded”的错误。具体的刷新方法根据使用的编程语言而异。题目大意:这是一个交互式问题。游戏规则如下: 1. 有一个长度为n的整数数组a。 2. 游戏由多轮组成,每轮如下进行: - 第一名玩家选择一个大于0的a[i]。如果没有这样的i,则第一名玩家输,游戏结束。 - 第二名玩家选择一个不等于i且大于0的a[j]。如果没有这样的j,则第二名玩家输,游戏结束。 - 设d=min(a[i],a[j]),将a[i]和a[j]同时减少d,然后进行下一轮。 3. 游戏在有限轮后一定会结束。 你需要选择扮演哪一名玩家(第一名或第二名),并赢得游戏。 输入输出数据格式: 输入: - 第一行包含一个整数n(1≤n≤300),表示数组a的长度。 - 第二行包含n个整数a[1],a[2],...,a[n](1≤a[i]≤300),表示数组a。 输出: - 第一行输出一个字符串,"First"或"Second",表示你选择的玩家。 - 之后的每一行,根据你选择的玩家,输出相应的i或j。 交互过程: - 如果你扮演第一名玩家,你需要在每一轮开始时输出一个整数i(1≤i≤n),然后读取一个整数j(-1≤j≤n)。 - 如果j=-1,则你做出了错误的移动。此时你的程序应立即终止。 - 如果j=0,则第二名玩家无法做出正确的移动,你赢得游戏。此时你的程序也应立即终止。 - 否则,j是第二名玩家选择的下标,你应继续进行下一轮。 - 如果你扮演第二名玩家,你需要在每一轮开始时读取一个整数i(-1≤i≤n)。 - 如果i=-1,则你在上一轮做出了错误的移动(这不会发生在第一轮)。此时你的程序应立即终止。 - 如果i=0,则第一名玩家无法做出正确的移动,你赢得游戏。此时你的程序也应立即终止。 - 否则,i是第一名玩家选择的下标。此时你应输出一个整数j(1≤j≤n),然后继续进行下一轮。 注意:在输出i或j后,不要忘记输出换行符,并刷新输出缓冲区,否则你将得到“Idleness limit exceeded”的错误。具体的刷新方法根据使用的编程语言而异。