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 ...
随机推荐
- openwrt gstreamer实例学习笔记(六. gstreamer Pads及其功能)
一:概述 如我们在Elements一章中看到的那样,Pads是element对外的接口.数据流从一个element的source pad到另一个element的sink pad.pads的功能(cap ...
- c++string 输入换行符
string 一次只能输入一行,不含换行符.可以自己添加换行符 和输入行数.例如:#include <iostream>#include <string>using names ...
- iOS之Prefix.pch
本文转载至 http://blog.csdn.net/lvxiangan/article/details/21325093 Prefix.pch的作用和用法 Hello World_Prefix. ...
- mac Git本地服务器配置
本文转载至 http://blog.csdn.net/piziliweiguang/article/details/9311791 XCode 默认支持 Git 作为代码仓库,当我们新建一个仓库的 ...
- HBase协处理器同步二级索引到Solr
一. 背景二. 什么是HBase的协处理器三. HBase协处理器同步数据到Solr四. 添加协处理器五. 测试六. 协处理器动态加载 一. 背景 在实际生产中,HBase往往不能满足多维度分析,我们 ...
- Record is locked by another user
Oracle修改表中记录时出现record is locked by another user的问题 在操作表时没有commit,导致表被锁,只要执行下面两行语句,就可以了将行锁解锁了. Select ...
- NettyIO
- [转]GPS NEMA 0183协议
一. NMEA0183标准语句(GPS常用语句) $GPGGA例:$GPGGA,092204.999,4250.5589,S,14718.5084,E,1,04,24.4,19.7,M,,,,0000 ...
- mysql 发生系统错误1067
一般是由配置文件错误语法不正确引起的,如my.ini本人在mysql mysql-5.6.29-winx64 配置过程中遇到“发生系统错误1067”主要由于下面两个目录写的格式不正确引起的正确写法如下 ...
- iOS的基本框架