CF1839E.Decreasing Game
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an interactive problem.
Consider the following game for two players:
- Initially, an array of integers a1,a2,…,an 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 ai>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=i such that aj>0. If there is no such j, the second player loses the game (the first player wins) and game ends.
- Let d=min(ai,aj). The values of ai and aj 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.
这是一个交互式问题。
考虑以下两人参与的游戏:
- 最初,黑板上写有一个长度为 n 的整数数组 a1,a2,…,an。
- 游戏由若干轮组成。每一轮中,发生如下事件:
- 先手玩家选择任意下标 i,满足 ai>0。若不存在这样的 i,则先手玩家输掉游戏(后手玩家获胜),游戏结束。
- 后手玩家选择任意下标 j=i,满足 aj>0。若不存在这样的 j,则后手玩家输掉游戏(先手玩家获胜),游戏结束。
- 令 d=min(ai,aj)。将 ai 和 aj 同时减少 d,然后进入下一轮。
可以证明,该游戏总会在有限轮后结束。
你需要选择自己扮演哪一方(先手或后手),并赢得游戏。
输入格式
The first line contains a single integer n (1≤n≤300) — the length of array a.
The second line contains n integers a1,a2,…,an (1≤ai≤300) — array a.
第一行包含一个整数 n(1≤n≤300)—— 数组 a 的长度。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤300)—— 数组 a。
输入输出样例
输入#1
4 10 4 6 3 3 1 0
输出#1
First 1 2 4
输入#2
6 4 5 5 11 3 2 2 5 4 6 1 0
输出#2
Second 4 4 3 1 3
说明/提示
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(a1,a3)=min(10,6)=6 is calculated. Elements a1 and a3 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(a2,a1)=min(4,4)=4 is calculated. Elements a2 and a1 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=4 such that aj>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.
在第一个样例中,n=4,数组 a 为 [10,4,6,3]。游戏过程如下:
- 读入数组 a 后,选手程序选择作为先手玩家,输出 "First"。
- 第一轮:先手玩家选择 i=1,后手玩家选择 j=3。计算 d=min(a1,a3)=min(10,6)=6。将元素 a1 和 a3 各减去 6。数组 a 变为 [4,4,0,3]。
- 第二轮:先手玩家选择 i=2,后手玩家选择 j=1。计算 d=min(a2,a1)=min(4,4)=4。将元素 a2 和 a1 各减去 4。数组 a 变为 [0,0,0,3]。
- 第三轮:先手玩家选择 i=4。此时不存在满足 j=4 且 aj>0 的下标 j,因此后手玩家无法进行合法操作,先手玩家获胜。评测程序输出 j=0。选手程序读入该值后终止。
在第二个样例中,n=6,数组 a 为 [4,5,5,11,3,2]。游戏过程如下:
- 选手程序选择作为后手玩家,输出 "Second"。
- 第一轮:i=2,j=4,a=[4,0,5,6,3,2]。
- 第二轮:i=5,j=4,a=[4,0,5,3,0,2]。
- 第三轮:i=4,j=3,a=[4,0,2,0,0,2]。
- 第四轮:i=6,j=1,a=[2,0,2,0,0,0]。
- 第五轮:i=1,j=3,a=[0,0,0,0,0,0]。
- 第六轮:先手玩家无法进行合法操作,后手玩家获胜。评测程序输出 i=0。选手程序读入该值后终止。
注意:该样例交互中包含额外的空行以增强可读性。实际交互中不包含任何空行,你也不应输出任何额外的空行。
输入解题思路,AI测评打分。不知道怎么写?