I am a slow walker,but I never walk backwards. Abraham Lincoln

GeekZRF

Codeforces 792B. Counting-out Rhyme

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 ≤ 100, 1 ≤ 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 5
10 4 11 4 1
output
4 2 5 6 1 
input
3 2
2 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.

题目链接:http://codeforces.com/problemset/problem/792/B

提意:编号1~n的n个人人围成一个圈。k此操作,每次操作为将执行者后面的第a个人剔除出去,下一次的执行者为剔除出去的后一个人,第一次操作的执行者编号为1。

思路:模拟。将a对cou取模,cou为每次操作后的剩余人数。

代码:

复制代码
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int sign[200];
int main()
{
    int n,k;
    int a;
    scanf("%d%d",&n,&k);
    int cou=n,start=0;
    memset(sign,0,sizeof(sign));
    for(int i=1; i<=k; i++)
    {
        scanf("%d",&a);
        a=a%cou;
        int t=0;
        while(t<=a)
        {
            start++;
            if(start>n) start-=n;
            if(sign[start]) continue;
            if(t==a) {sign[start]=1;cout<<start<<" ";}
            t++;
        }
        cou--;
    }
    return 0;
}
View Code
复制代码

 

posted on   GeekZRF  阅读(280)  评论(0编辑  收藏  举报

编辑推荐:
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
阅读排行:
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· 程序员常用高效实用工具推荐,办公效率提升利器!
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 【译】WinForms:分析一下(我用 Visual Basic 写的)

导航

统计

点击右上角即可分享
微信分享提示