codeforces 792B
来源:互联网 发布:jquery 1.11.1.min.js 编辑:程序博客网 时间:2024/06/11 05:14
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.
- 题意:给你一个n,一个k,顺时针编号1-n,然后给你k个数,这k个数相当于k次操作,每次给编号换领导者和找出删除的人。一次操作之后,领导者编号变为1,领导者之前的编号就是要求删除的数,其实就是模拟就行了。具体操作见代码。
- 代码:
#include<bits/stdc++.h>typedef long long LL;using namespace std;const int maxn=120;int a[maxn],b[maxn],c[maxn];int main(){ int n,k; while(scanf("%d%d",&n,&k)!=EOF) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); for(int i=1;i<=n;i++) { a[i]=i; } int x; int ans=0; while(k--) { int num=1; scanf("%d",&x); int t=x%n+2; int k=t-1; b[ans]=a[t-1];//目标值 for(int i=t;i<=n;i++)//变换新序列的前半部分 { c[num++]=a[i]; } for(int i=1;i<t;i++)//变换新序列的后半部分 { c[num++]=a[i]; } ans++; n--; for(int i=1;i<=n;i++) { a[i]=c[i]; } memset(c,0,sizeof(c)); } for(int i=0;i<ans;i++) { printf("%d ",b[i]); } printf("\n"); }}
- codeforces 792B
- codeforces 792B
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- Codeforces Educational Round #18(Codeforces 792 A B C D)
- CodeForces 792B Counting-out Rhyme
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- Codeforces 1B - Spreadsheet
- 鼠标拾取功能
- Spring框架的概述
- 常用正则表达式
- c语言常用知识1
- h3c防火墙m-g2-100安全优化配置1
- codeforces 792B
- linux下源代码编译安装LAMP框架
- Codeforces Beta Round #4 (Div. 2 Only) C. Registration system hash
- HTML
- 跨平台shader 编译
- [乐意黎原创] Mysql使用UTF8编码时让某字段使用中文排序(UTF8按字段拼音首字母排序)
- Spring简单整合redis
- git本地控制分支权限
- 踩过的一个android原生“坑”