Description

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.

题意:n个学生,我们从0开始数ai个数字,输出下一个数字,然后删除输出的数字,数到的数字作为新的起点再次循环这个操作,好乱啊,看Note吧

解法:模拟

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m;
ll a[];
ll maxn=(<<)-;
vector<ll>q;
bool fun(int i)
{
return (i > ) && ((i & (i - )) == );
}
int main()
{
string s;
cin>>n>>m;
for(ll i=;i<=n;i++)
{
q.push_back(i);
}
ll ans=;
for(ll i=;i<=m;i++)
{
cin>>a[i];
ll x=(a[i]%q.size()+ans)%q.size();
cout<<q[x]<<" ";
ans=x;
q.erase(q.begin()+x);
}
return ;
}

Educational Codeforces Round 18 B的更多相关文章

  1. Educational Codeforces Round 18

    A. New Bus Route 题目大意:给出n个不同的数,问差值最小的数有几对.(n<=200,000) 思路:排序一下,差值最小的一定是相邻的,直接统计即可. #include<cs ...

  2. Educational Codeforces Round 18 D

    Description T is a complete binary tree consisting of n vertices. It means that exactly one vertex i ...

  3. Educational Codeforces Round 18 A

    Description There are n cities situated along the main road of Berland. Cities are represented by th ...

  4. Educational Codeforces Round 18 C. Divide by Three DP

    C. Divide by Three   A positive integer number n is written on a blackboard. It consists of not more ...

  5. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  6. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  7. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  8. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  9. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

随机推荐

  1. html使用代码大全

    <DIV style="FONT-SIZE: 9pt">1)贴图:<img src="图片地址">1)首行缩进2格:<p styl ...

  2. Axure Base 08 动态面板的用途

    写了几个Axure教程之后发现,可能教程的起点有些高了,过分的去讲效果的实现,而忽略了axure功能以及基础元件的使用,那么从这个教程开始,把这些逐渐的展开讲解. 关于动态面板 动态面板是axure原 ...

  3. 关于在PHP中当一个请求未完成时,再发起另一个请求被阻塞的问题

    最近做项目的时候遇到个问题,就是做阿里云oss大文件上传进度条显示,因为要实时查询上传分片进度,所以在上传的同时必须要再发起查询的请求,但是一直都是所有分片上传完成后查询的请求才执行,刚开始以为是阿里 ...

  4. setTimeout 传递的方法

    function waitExe(param){ if(time < 20){ time ++; $("#content").html(time); var self=thi ...

  5. maven统一配置

    <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> &l ...

  6. js遍历map

    //火狐控制台打印输出: Object { fileNumber="文件编号", fileName="文件名称"} console.log(map); for( ...

  7. uCos临界区保护

    定义有三种method,stm32f4采用的是第三种:将当前中断的状态标志保存在一个局部变量cpu_sr中,然后再关闭中断.cpu_sr是一个局部变量,存在于所有需要关中断的函数中.注意到,在使用了该 ...

  8. 使用sql compare生成的sql语句

    创建表以及主键 判断表是否存在 OBJECT_ID 判断主键是否存在 SELECT 1 FROM sys.indexes WHERE name = N'PK_LISA_NoUseWebpartRepl ...

  9. 应用程序启动器 “sublime_text.desktop“ 还没有被标记为 信任。如果您不知道这个文件的来源,那么启动它可能会不安全。解决sublime在ubuntu中不支持中文输入问题。

    1.下载 git clone https://github.com/lyfeyaj/sublime-text-imfix.git 2.进行一些处理 cd ~/sublime-text-imfix su ...

  10. I.MX6 Android 5.1.1 下载、编译

    /************************************************************************* * I.MX6 Android 5.1.1 下载. ...