Codeforces 792B. Counting-out Rhyme
1 second
256 megabytes
standard input
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.
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 5
10 4 11 4 1
4 2 5 6 1
3 2
2 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.
题目链接: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的更多相关文章
- Codeforces 893E - Counting Arrays
893E - Counting Arrays 思路:质因子分解. 对于每个质因子,假设它有k个,那么求把它分配到y个数上的方案数. 相当于把k个小球分配到y个盒子里的方案数. 这个问题可以用隔板法(插 ...
- Codeforces 372B Counting Rectangles is Fun
http://codeforces.com/problemset/problem/372/B 题意:每次给出一个区间,求里面有多少个矩形 思路:预处理,sum[i][j][k][l]代表以k,l为右下 ...
- [CodeForces 372A] Counting Kangaroos is Fun
题目链接:http://codeforces.com/problemset/problem/372/A 二分思想 AC代码: #include <cstdio> #include < ...
- Codeforces 893E Counting Arrays:dp + 线性筛 + 分解质因数 + 组合数结论
题目链接:http://codeforces.com/problemset/problem/893/E 题意: 共q组数据(q <= 10^5),每组数据给定x,y(x,y <= 10^6 ...
- Codeforces 372B Counting Rectangles is Fun:dp套dp
题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问( ...
- CodeForce-792B Counting-out Rhyme(模拟)
Counting-out Rhyme CodeForces - 792B 题意: n 个孩子在玩一个游戏. 孩子们站成一圈,按照顺时针顺序分别被标号为 1 到 n.开始游戏时,第一个孩子成为领导. 游 ...
- 3.26-3.31【cf补题+其他】
计蒜客)翻硬币 //暴力匹配 #include<cstdio> #include<cstring> #define CLR(a, b) memset((a), (b), s ...
- WC2019 题目集
最近写的一些 WC2019 上讲的一些题.还是怕忘了,写点东西记录一下. LOJ2983 「WC2019」数树 题意 本题包含三个问题: 问题 0:已知两棵 \(n\) 个节点的树的形态(两棵树的节点 ...
- Codeforces 372 B. Counting Rectangles is Fun
$ >Codeforces \space 372 B. Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...
随机推荐
- java语言 找出文章中出现次数最多的单词
package english; import java.io.File; import java.util.Scanner; import java.io.FileNotFoundException ...
- Beanutils.copyProperties( )的使用与优化
1.使用原因 因为现在都是前后端分离所以我们在响应APP端或者前端的时候会维护一套VO,那么DTO到VO的转换便是一堆get... set...这样的代码,比如好几个地方用到的话还要去复制粘贴来转换. ...
- php优化-》常用到的部分优化
1.循环内部尽可能不要声明变量: 2.在可以用PHP内部字符串操作函数的情况下,尽量不要用正则表达式: 3.foreach效率更高,尽量用foreach代替while和for循环: 4.用单引号替代双 ...
- The APK failed to install. Error:Could not parse error string.
问题一: The APK failed to install. Error:Could not parse error string. 今天拖拽自己的apk到模拟器上运行,报上述错误. 搜索解决方案. ...
- 用jQuery实现轮播图效果,js中的排他思想
---恢复内容开始--- jQuery实现轮播图不用单独加载. 思路: a. 通过$("#id名");选择需要的一类标签,获得一个伪数组 b.由于是伪数组的原因,而对数组的处理最多 ...
- JavaScript Drag处理
[JavaScript Drag处理] 在拖动目标上触发事件 (源元素): ondragstart - 用户开始拖动元素时触发 ondrag - 元素正在拖动时触发 ondragend - 用户完成元 ...
- msf客户端渗透(五):注册表
先获取到一个session 上传nc到被攻击主机上 建立一个键值 创建一个策略 kali上查看是否成功创建键值 后台开启cmd 查看防火墙的策略 打开防火墙的端口 添加一条防火墙策略 在win7上查看 ...
- Python 豆瓣日记爬取
无聊写了个豆瓣日记的小爬虫,requests+bs4. cookies_src可填可不填,主要是为了爬取仅自己可见的日记. url填写的是日记页面,即https://www.douban.com/pe ...
- CentOS 查找某个软件安装路径
1.通过rpm查看 查看软件是否安装.首先我们需要查看软件是否已经安装,或者说查看安装的软件包名称.如查找是否安装mysql 2.接着根据 rpm -ql 列出软件包安装的文件 3.综合上述以上的问题 ...
- Wannafly挑战赛13 B:Jxc军训(逆元)
题目描述 在文某路学车中学高一新生军训中,Jxc正站在太阳下站着军姿,对于这样的酷热的阳光,Jxc 表示非常不爽. Jxc将天空看做一个n*n的矩阵,此时天上有m朵云,这些云会随机分布在m个不同的位置 ...