Educational Codeforces Round 18 B
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.
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.
题意: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的更多相关文章
- Educational Codeforces Round 18
A. New Bus Route 题目大意:给出n个不同的数,问差值最小的数有几对.(n<=200,000) 思路:排序一下,差值最小的一定是相邻的,直接统计即可. #include<cs ...
- Educational Codeforces Round 18 D
Description T is a complete binary tree consisting of n vertices. It means that exactly one vertex i ...
- Educational Codeforces Round 18 A
Description There are n cities situated along the main road of Berland. Cities are represented by th ...
- 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 ...
- 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 ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
随机推荐
- 使网页适应UIWebView的宽度
比較简单的做法是:在- (void)webViewDidFinishLoad:这种方法中,改动JavaScript的值: //UIWebViewDelegate - (void)webViewDidF ...
- Testng 运行报错:"Total tests run: 0, Failures: 0, Skips: 0"以及找不到class文件的问题
"Total tests run: 0, Failures: 0, Skips: 0" This means that there were no tests executed a ...
- 设计模式学习笔记——Prototype原型模式
原型模型就是克隆. 还有深克隆.浅克隆,一切听上去都那么耳熟能详.
- Web 监听器
什么事web 监听器? Servlet规范中定义的一种特殊类 用于监听ServletContext.HttpSession和ServletRequest等象的创建与销毁的事件 用监听域对象的属性发生修 ...
- yum报错File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:
原因:学python的时候,把centos7自带的python2.7改成了python3.6.2.而yum使用的是python2,所以会出现yum报错. 解决方法: 在文件/usr/bin/yum./ ...
- MySQL table
-- 使用数据库hr use hr; -- 在数据库中创建表-- ------------------------------------JOBS表-------------------------- ...
- field 属性操作
首先必须明一点 Field类主要是用来辅助获取和操作类的属性的! 1.怎么通过反射获取类的属性 先来看JDK提供的方法有如下几种: a)Class.getDeclaredField(String na ...
- Ruby中任务构建工具rake的入门学习教程
参考:http://www.jb51.net/article/81476.htm Rake简介 Rake的意思是Ruby Make,一个用ruby开发的代码构建工具. 但是,为什么Ruby需要Rake ...
- react native与原生的交互
一.交互依赖的重要组件 react native 中如果想要调用ios 中相关的方法,必须依赖一个重要的组件nativemodules import { NativeModules } from ' ...
- SDUT 周赛 神奇的树(简单题 注意数据类型的溢出 )
神奇的树 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 SDUT有一颗神奇的苹果树.假如某天早上这树上有x个苹果,那么这树这一天 ...