codeforces 792B

来源:互联网 发布:jquery 1.11.1.min.js 编辑:程序博客网 时间:2024/06/11 05:14
B. Counting-out Rhyme
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ai 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 ai = 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.

Input

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

The next line contains k integer numbers a1, a2, ..., ak (1 ≤ ai ≤ 109).

Output

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

Examples
input
7 510 4 11 4 1
output
4 2 5 6 1 
input
3 22 5
output
3 2 
Note

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.
  • 题意:给你一个n,一个k,顺时针编号1-n,然后给你k个数,这k个数相当于k次操作,每次给编号换领导者和找出删除的人。一次操作之后,领导者编号变为1,领导者之前的编号就是要求删除的数,其实就是模拟就行了。具体操作见代码。
  • 代码:
  • #include<bits/stdc++.h>typedef long long LL;using namespace std;const int maxn=120;int a[maxn],b[maxn],c[maxn];int main(){    int n,k;    while(scanf("%d%d",&n,&k)!=EOF)    {        memset(a,0,sizeof(a));        memset(b,0,sizeof(b));        memset(c,0,sizeof(c));        for(int i=1;i<=n;i++)        {            a[i]=i;        }        int x;        int ans=0;        while(k--)        {            int num=1;            scanf("%d",&x);            int t=x%n+2;            int k=t-1;            b[ans]=a[t-1];//目标值            for(int i=t;i<=n;i++)//变换新序列的前半部分            {                c[num++]=a[i];            }            for(int i=1;i<t;i++)//变换新序列的后半部分            {                c[num++]=a[i];            }            ans++;            n--;            for(int i=1;i<=n;i++)            {                a[i]=c[i];            }            memset(c,0,sizeof(c));        }        for(int i=0;i<ans;i++)        {            printf("%d ",b[i]);        }        printf("\n");    }}

0 0