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[];
int main()
{
int n,k;
int a;
scanf("%d%d",&n,&k);
int cou=n,start=;
memset(sign,,sizeof(sign));
for(int i=; i<=k; i++)
{
scanf("%d",&a);
a=a%cou;
int t=;
while(t<=a)
{
start++;
if(start>n) start-=n;
if(sign[start]) continue;
if(t==a) {sign[start]=;cout<<start<<" ";}
t++;
}
cou--;
}
return ;
}

Codeforces 792B. Counting-out Rhyme的更多相关文章

  1. Codeforces 893E - Counting Arrays

    893E - Counting Arrays 思路:质因子分解. 对于每个质因子,假设它有k个,那么求把它分配到y个数上的方案数. 相当于把k个小球分配到y个盒子里的方案数. 这个问题可以用隔板法(插 ...

  2. Codeforces 372B Counting Rectangles is Fun

    http://codeforces.com/problemset/problem/372/B 题意:每次给出一个区间,求里面有多少个矩形 思路:预处理,sum[i][j][k][l]代表以k,l为右下 ...

  3. [CodeForces 372A] Counting Kangaroos is Fun

    题目链接:http://codeforces.com/problemset/problem/372/A 二分思想 AC代码: #include <cstdio> #include < ...

  4. Codeforces 893E Counting Arrays:dp + 线性筛 + 分解质因数 + 组合数结论

    题目链接:http://codeforces.com/problemset/problem/893/E 题意: 共q组数据(q <= 10^5),每组数据给定x,y(x,y <= 10^6 ...

  5. Codeforces 372B Counting Rectangles is Fun:dp套dp

    题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问( ...

  6. CodeForce-792B Counting-out Rhyme(模拟)

    Counting-out Rhyme CodeForces - 792B 题意: n 个孩子在玩一个游戏. 孩子们站成一圈,按照顺时针顺序分别被标号为 1 到 n.开始游戏时,第一个孩子成为领导. 游 ...

  7. 3.26-3.31【cf补题+其他】

      计蒜客)翻硬币 //暴力匹配 #include<cstdio> #include<cstring> #define CLR(a, b) memset((a), (b), s ...

  8. WC2019 题目集

    最近写的一些 WC2019 上讲的一些题.还是怕忘了,写点东西记录一下. LOJ2983 「WC2019」数树 题意 本题包含三个问题: 问题 0:已知两棵 \(n\) 个节点的树的形态(两棵树的节点 ...

  9. Codeforces 372 B. Counting Rectangles is Fun

    $ >Codeforces \space 372 B.  Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...

随机推荐

  1. Linux下Shell命令加减乘除计算

    使用 expr命令 (其中做乘的时候*号要用斜杠进行转义) 除以 [hadoop-user@hadoop1]$ echo `expr 9 / 3`             3加 [hadoop-use ...

  2. Js笔记(对象,构造函数,原型,原型链,继承)及一些不熟悉的语法

    对象的特性: 1.唯一标识性,即使完全不一样的对象,内存地址也不同,所以他们不相等 2.对象具有状态,同一个对象可能处在不同状态下 3.对象具有行为,即对象的状态可能因为他的行为产生变迁 Js直到es ...

  3. node搭建简单的本地服务器

    首先要安装node,方法很多,可以去网上找找,可以直接去官网下载安装,新版本的node是自带npm的: 安装好以后,新建一个js文件,名为server.js: let http = require(' ...

  4. Django2.1在根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete'

    解决办法: a=models.ForeignKey('BookInfo',on_delete=models.CASCADE,) 即在外键值的后面加上 on_delete=models.CASCADE ...

  5. HDU-1257.最少拦截系统(基础DP)

    本题大意:给出n和n个整数,让你求出其中不上升子序列的个数. 本题思路:用dp[ i ]保存第i个防御系统攻击的最低的导弹,遍历数组,遇到更低的导弹则更新最小值,否则新加一个系统用来防御,并且更新最小 ...

  6. rear

    rear - 必应词典 美[rɪr]英[rɪə(r)] v.抚养:养育:饲养:培养 n.屁股:后部:臀部 adj.后面的:后部的 网络背面:后方:后轮 变形过去分词:reared:现在分词:reari ...

  7. bootstrap-table 使用遇到的问题总结

    问题一:右上角button样式自定义 方法: //修改bootstrap-table右上角按钮样式 $(".table-box .columns-right button").re ...

  8. ACM-ICPC 2018 南京赛区网络预赛 L.Magical Girl Haze(分层最短路)

    There are N cities in the country, and M directional roads from u to v(1≤u,v≤n). Every road has a di ...

  9. css控制div上浮下落

    CSS3 示例:http://www.w3school.com.cn/cssref/pr_keyframes.asp 以下是代码: <!DOCTYPE html> <html> ...

  10. mysql-5.7.21安装和配置方法

      到MySQL官网下载MySQL 5.7.21的版本,下载地址:https://dev.mysql.com/downloads/mysql/ .根据自己的系统下载相应的32位或64位的版本. 将下载 ...