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. openwrt procd 运行的一些log

    void procd_inittab(void) { #define LINE_LEN 128 FILE *fp = fopen(tab, "r"); struct init_ac ...

  2. 项目Alpha冲刺(团队9/10)

    项目Alpha冲刺(团队9/10) 团队名称: 云打印 作业要求: 项目Alpha冲刺(团队) 作业目标: 完成项目Alpha版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 ...

  3. Hadoop之HDFS文件操作

    摘要:Hadoop之HDFS文件操作常有两种方式.命令行方式和JavaAPI方式.本文介绍怎样利用这两种方式对HDFS文件进行操作. 关键词:HDFS文件    命令行     Java API HD ...

  4. 有遍历struct中字段信息的函数或方法

    例:struct a{int a;char b[10];double c;}; 在程序中只知道一个结构 a 的指针, 有没有函数能通过结构的名字 和 指向结构的指针 随次得到 结构中的变量类型 和 变 ...

  5. 【ACdream】1157 Segments cdq分治

    Segments   Problem Description 由3钟类型操作:1)D L R(1 <= L <= R <= 1000000000) 增加一条线段[L,R]2)C i ...

  6. cocos2dx学习进度

    将cocos2dx实战上面的例子都自己过一遍,手动敲一边里面的代码,瓦片地图,地图滚动,碰撞,容器类,现在搞到了fileUtils相关的了,哦,官方叫做数据持久化,一不小心就6点了,时间过得太快了,看 ...

  7. xamarin.android searchview的一些用法

    前言 searchview是安卓常用的搜索控件,网上有很多关于searchview都是java的,所以我参看xamaroin官网的一些demo总结一些方法. 导读 1.如何创建一个searchview ...

  8. 李雅普诺夫函数 LyapunovFunction 李雅普诺夫意义下的稳定性

    https://zh.wikipedia.org/zh-hans/李亞普諾夫函數 李雅普诺夫函数(Lyapunov function)是用来证明一动力系统或自治微分方程稳定性的函数.其名称来自俄罗斯数 ...

  9. C/C++ 操作符优先级

    不能光转贴,有空要熟悉之后,要写点心得.现在发现 . 的优先级确实很高. C: Precedence Operator Description Associativity 1 ++ -- Suffix ...

  10. poj 3585 Accumulation Degree(二次扫描和换根法)

    Accumulation Degree 大致题意:有一棵流量树,它的每一条边都有一个正流量,树上所有度数为一的节点都是出口,相应的树上每一个节点都有一个权值,它表示从这个节点向其他出口可以输送的最大总 ...