CodeForces
来源:互联网 发布:审美差异知乎 编辑:程序博客网 时间:2024/06/05 18:36
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.
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).
Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step.
7 510 4 11 4 1
4 2 5 6 1
3 22 5
3 2
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.
ac代码:
#include <bits/stdc++.h>#include <queue>#define ll long longusing namespace std;int n,k;int a[105];int main(){while(~scanf("%d%d",&n,&k)){queue <int>qu;for(int i=1;i<=k;i++){scanf("%d",&a[i]);}for(int i=1;i<=n;i++){qu.push(i);}int aun=n;int cnt=0;int kai[110];for(int i=1;i<=k;i++){int tmp=(a[i]+1)%aun;if(tmp==0)tmp=aun;while(tmp--){int ss=qu.front();qu.pop();if(tmp==0){kai[cnt]=ss;cnt++;aun--;}else{qu.push(ss);}}}printf("%d",kai[0]);for(int i=1;i<cnt;i++){printf(" %d",kai[i]);}printf("\n");}return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- C++基础问题
- 流体力学与流体计算力学基础(一)
- HDOJ1221 计算几何入门题
- 从Tiny4412--mma7660 gsensor驱动探索Linux内核I2C总线驱动框架
- C语言之随机数生成
- CodeForces
- Hive的Map端连接方法
- 登录用户名和密码校验回来
- 528_计算圆弧上某一点的坐标
- mysql根据用户id分组读取两列的总和倒叙排列后取前十条sql语句
- 【编程题】京东校招 2017 集合
- 关于Python里的super用法研究
- 过滤器和拦截器的区别
- HTML 5离线Web应用(整理)