QOJ.ac

QOJ

Límite de tiempo: 3 s Límite de memoria: 512 MB Puntuación total: 100 Interactivo

#2277. 石头

Estadísticas

当 Ankica 终于抓到 Branko 时,他拒绝购买她的报纸,并要求玩一个不同的游戏,因为上一个游戏被操纵了。Ankica 天真地建议玩另一个涉及石头的游戏,但 Branko 疑心很重,决定彻底改变规则。

该游戏涉及 $N$ 堆石头,第 $i$ 堆有 $a_i$ 个石头,玩家轮流从某一堆中移除若干个石头。移除最后一颗石头的玩家获胜。

游戏的特别之处在于,玩家在特定回合中必须从中移除石头的堆是由对方指定的。

更准确地说,游戏的回合从 1 开始递增,过程如下:

  • 奇数回合:Branko 首先指定一堆非空的石头。然后 Ankica 从该堆中移除至少一颗(至多全部)石头。
  • 偶数回合:Ankica 首先指定一堆非空的石头。然后 Branko 从该堆中移除至少一颗(至多全部)石头。

Branko 找来一堆石头,分成了若干堆,然后他们开始游戏。作为一名职业玩家,Ankica 很快意识到初始的石头配置对她来说是必胜的,也就是说,无论 Branko 在游戏的其余部分如何操作,她都能获胜。

你能在 Ankica 的处境下赢得比赛吗?

交互

这是一个交互式任务。你的程序必须与组织者编写的程序进行通信,该程序扮演 Branko 的角色。当然,你的程序应扮演 Ankica 的角色,并确保她赢得比赛。

你的程序首先应从标准输入读取游戏的初始状态。初始状态分两行给出。第一行包含一个整数 $N$,第二行包含 $N$ 个空格分隔的正整数 $a_1, a_2, \dots, a_N$。

现在,游戏开始。请记住,你的程序扮演 Ankica,这意味着它应该根据当前回合是奇数还是偶数采取不同的行动。

在奇数回合期间:

  • 你的程序应首先读取一个整数 $k$。如果此时所有堆都为空,则 $k$ 将等于 $-1$,你应该终止程序,因为这意味着游戏结束且你输了。否则,$k$ ($1 \le k \le N$) 表示你(Ankica)必须从第 $k$ 堆中移除若干个石头。保证此时第 $k$ 堆不为空。设第 $k$ 堆当前剩余的石头数量为 $s_k$。
  • 你的程序随后应输出一个整数 $x$ ($1 \le x \le s_k$),表示你希望从第 $k$ 堆中移除的石头数量,并刷新输出。

在偶数回合期间:

  • 你的程序应首先写入一个整数 $l$ 并刷新输出。如果此时所有堆都为空,则 $l$ 必须等于 $-1$,你应该终止程序,因为这意味着游戏结束且你赢了。否则,$l$ ($1 \le l \le N$) 表示你强制 Branko 从第 $l$ 堆中移除若干个石头。此时第 $l$ 堆必须不为空。设第 $l$ 堆当前剩余的石头数量为 $s_l$。
  • 你的程序随后应读取一个整数 $y$ ($1 \le y \le s_l$),表示 Branko 从第 $l$ 堆中移除的石头数量。

保证初始状态确保你(Ankica)无论 Branko 如何操作都能赢得比赛。

说明:你可以从评测系统中下载示例源代码,该代码能与组织者编写的程序正确交互(包括输出刷新),并解决第一个示例。

子任务

设 $M = \max(a_1, a_2, \dots, a_N)$。

子任务 分值 数据范围
1 12 $1 \le N, M \le 7$
2 13 $1 \le N \le 12, 1 \le M \le 500$
3 15 $1 \le N, M \le 500$, 且对于所有 $1 \le i, j \le N$ 有 $a_i = a_j$
4 60 $1 \le N, M \le 500$

样例

样例 1

1
4
1
4
-1

样例 2

3
1 1 5
3
5
1
1
2
1
-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.