QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 100

#3925. 点兵点将

统计

“Eeny meeny miny moe” 是一首著名的英语童谣,常被孩子们用来“随机”选择团队成员。它有许多变体,其中一种如下:

Eeny, meeny, miny, moe, Catch a tiger by the toe. If he hollers, let him go, Eeny, meeny, miny, moe.

许多语言中都存在类似的诗句,例如芬兰语的“Ulle dulle dof”、挪威语的“Akka bakka bonka rakka”以及瑞典语的“Ole dole doff”。

游戏需要选出两支队伍,童谣用于一次选出一名孩子加入队伍,两支队伍交替进行,直到所有孩子都被选中。孩子们围成一个圆圈站立。在每一轮选择中,我们从圆圈中顺时针方向开始数数,童谣中的每一个词对应跳过一个孩子,直到最后一个词。与最后一个词对应的孩子被选中加入当前队伍,然后开始下一轮。除第一轮外,后续每一轮的计数都从上一轮被选中的孩子之后的下一个剩余孩子(顺时针方向)开始。参见图 E.1 示例。

给定这样的童谣和一组孩子,你能告诉我们哪些孩子会进入哪支队伍吗?

图 E.1:样例输入 1 的前三轮演示。在第 1 轮和第 3 轮中,Alvar 和 Rakel 被选入第一支队伍;在第 2 轮中,Lisa 被选入第二支队伍。在第 4 轮(未显示)中,只剩下 Kalle,他被选入第二支队伍。

输入格式

输入的第一行包含童谣,由一系列以空格分隔的单词组成。 输入的第二行包含一个整数 $n$ ($1 \le n \le 100$),表示孩子的数量。接下来是孩子的名字,每行一个。孩子们按顺时针顺序给出,第一个列出的孩子是第一轮开始计数时的起点。

所有单词和名字仅由大小写字母 ‘A’-‘Z’ 和 ‘a’-‘z’ 组成。没有输入行是空的,且长度不超过 100 个字符(不包括行尾的换行符)。

输出格式

输出两支队伍,首先输出第一个成员被选出的那支队伍。对于每支队伍,先输出该队中孩子的数量,然后按被选入队伍的顺序输出孩子们的名字。

样例

输入 1

eeny meeny miny
4
Kalle
Lisa
Alvar
Rakel

输出 1

2
Alvar
Rakel
2
Lisa
Kalle

输入 2

Every Other
3
a
b
c

输出 2

2
b
c
1
a

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.