QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 2048 MB Puntuación total: 100

#8655. 投掷游戏

Estadísticas

Daenerys 经常发明一些游戏,来帮助她教二年级的计算机科学班级了解该学科的各个方面。在本周的课程中,她让孩子们围成一个圆圈,并(小心地)传递一颗石化的龙蛋。

$n$ 个孩子围成一圈,按顺时针方向编号为 $0$ 到 $n-1$(毕竟这是计算机科学课)。初始时,孩子 $0$ 持有龙蛋。Daenerys 会喊出以下两种指令之一:

  1. 一个数字 $t$,表示将龙蛋传给当前持蛋者顺时针方向第 $t$ 个位置的孩子,必要时进行环绕。如果 $t$ 为负数,则表示向逆时针方向传递。
  2. 短语 undo m,表示撤销最后 $m$ 次传递操作。注意,undo 指令不会撤销其他的 undo 指令;它们只会撤销上述第 1 点中描述的传递指令。

例如,如果有 $5$ 个孩子,老师喊出四条传递指令 8 -2 3 undo 2,传递过程将从孩子 $0$ 到孩子 $3$,然后从孩子 $3$ 到孩子 $1$,再从孩子 $1$ 到孩子 $4$。在此之后,undo 2 指令将导致龙蛋从孩子 $4$ 传回孩子 $1$,再从孩子 $1$ 传回孩子 $3$。如果 Daenerys 喊出 $0$(或 $n, -n, 2n, -2n$ 等),那么持有龙蛋的孩子只需将它垂直向上抛起,然后(小心地)接住它即可。

Daenerys 需要一个小程序来确定如果她的指令被正确执行,龙蛋最终会落在谁手中。如果指令执行不正确,别问孩子们会发生什么。

输入格式

输入包含两行。第一行包含两个正整数 $n$ 和 $k$ ($1 \le n \le 30, 1 \le k \le 100$),分别表示学生人数和 Daenerys 喊出的传递指令数量。接下来的第二行包含 $k$ 条传递指令。每条指令要么是一个整数 $p$ ($-10\,000 \le p \le 10\,000$),表示将龙蛋顺时针传递的位数;要么是 undo m ($m \ge 1$),表示撤销最后 $m$ 次传递操作。Daenerys 永远不会让孩子们撤销到游戏开始之前。

输出格式

显示游戏结束时持有龙蛋的孩子的编号。

样例

样例输入 1

5 4
8 -2 3 undo 2

样例输出 1

3

样例输入 2

5 10
7 -3 undo 1 4 3 -9 5 undo 2 undo 1 6

样例输出 2

2

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.