CF792B.Counting-out Rhyme

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out a__i people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.

For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and a__i = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.

You have to write a program which prints the number of the child to be eliminated on every step.

有 nn 个孩子围成一个圆圈,正在玩“数数淘汰”游戏。孩子们按顺时针方向编号为 11 到 nn。游戏开始时,第一个孩子(编号为 11)为当前领导者。游戏共进行 kk 轮。在第 ii 轮中,领导者从自己下一个人开始,沿顺时针方向数 aia_i 个人;被数到的第 aia_i 个人将被淘汰,而被淘汰者之后的下一个人将成为新的领导者。

例如,若当前圆圈中剩余的孩子编号为 [8, 10, 13, 14, 16][8,\,10,\,13,\,14,\,16],当前领导者为孩子 1313,且 ai=12a_i = 12,则数数过程最终落在孩子 1616 上,该孩子被淘汰;随后孩子 88 成为新的领导者。

你需要编写一个程序,输出每一轮中被淘汰孩子的编号。

输入格式

The first line contains two integer numbers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1).

The next line contains k integer numbers _a_1, _a_2, ..., a__k (1 ≤ a__i ≤ 109).

第一行包含两个整数 nn 和 kk(2≤n≤1002 \leq n \leq 100,1≤k≤n−11 \leq k \leq n-1)。

第二行包含 kk 个整数 a1, a2, …, aka_1,\,a_2,\,\dots,\,a_k(1≤ai≤1091 \leq a_i \leq 10^9)。

输出格式

Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step.

输出 k 个数,其中第 i 个数表示在第 i 步中被淘汰的孩子的数量。

输入输出样例

  • 输入#1

    7 5
    10 4 11 4 1

    输出#1

    4 2 5 6 1
  • 输入#2

    3 2
    2 5

    输出#2

    3 2

说明/提示

Let's consider first example:

  • In the first step child 4 is eliminated, child 5 becomes the leader.
  • In the second step child 2 is eliminated, child 3 becomes the leader.
  • In the third step child 5 is eliminated, child 6 becomes the leader.
  • In the fourth step child 6 is eliminated, child 7 becomes the leader.
  • In the final step child 1 is eliminated, child 3 becomes the leader.

我们先考虑第一个例子:

  • 第一步:淘汰孩子 4,孩子 5 成为领导者。
  • 第二步:淘汰孩子 2,孩子 3 成为领导者。
  • 第三步:淘汰孩子 5,孩子 6 成为领导者。
  • 第四步:淘汰孩子 6,孩子 7 成为领导者。
  • 最后一步:淘汰孩子 1,孩子 3 成为领导者。

输入解题思路,AI测评打分。不知道怎么写?

首页