CodeForces 450A 队列
Description
There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from
1 to n. The
i-th child wants to get at least ai candies.
Jzzhu asks children to line up. Initially, the i-th child stands at the
i-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
- Give m candies to the first child of the line.
- If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home.
- Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
Input
The first line contains two integers n, m(1 ≤ n ≤ 100; 1 ≤ m ≤ 100). The second line contains
n integers a1, a2, ..., an(1 ≤ ai ≤ 100).
Output
Output a single integer, representing the number of the last child.
Sample Input
5 2
1 3 1 4 2
4
6 4
1 1 2 2 3 3
6
Hint
Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets
2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home.
//队列
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue> using namespace std; struct node
{
int a,b;
} p,t;
int main()
{
queue<node> q;
int n,m;
while(~scanf("%d%d",&n,&m))
{
int top=-1;
for(int i=0; i<n; i++)
{
scanf("%d",&p.a);
p.b=i+1;
if(p.a-m>0)
{
p.a-=m;
q.push(p);
top=p.b;
}
}
// t=q.top();
// printf("%d\n",t.a);
if(top==-1)
printf("%d\n",n);
else
{
while(!q.empty())
{
t=q.front();
q.pop();
if(t.a-m>0)
{
t.a-=m;
q.push(t);
top=t.b;
}
}
printf("%d\n",top);
} }
}
CodeForces 450A 队列的更多相关文章
- codeforces 704A (队列模拟) Thor
题目:这里 题意:n个app,q个操作,当操作数type为1的时候表示y这个app推送了你一条消息,当操作数type为2的时候表示将y这个app已推送的所有消息都读完,当操作数为3的时候 表示将已经推 ...
- CodeForces 164 B. Ancient Berland Hieroglyphs 单调队列
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co ...
- Codeforces Round #189 (Div. 1) B. Psychos in a Line 单调队列
B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/p ...
- CodeForces 546C(队列)
CodeForces 546C Soldier and Cards Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I ...
- Codeforces Beta Round #6 (Div. 2 Only) 单调队列
题目链接: http://codeforces.com/contest/6/problem/E E. Exposition time limit per test 1.5 secondsmemory ...
- Codeforces 445A Boredom(DP+单调队列优化)
题目链接:http://codeforces.com/problemset/problem/455/A 题目大意:有n个数,每次可以选择删除一个值为x的数,然后值为x-1,x+1的数也都会被删除,你可 ...
- Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列
题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...
- Codeforces 1029B. Creating the Contest 动态规划O(nlogn)解法 及 单调队列O(n)解法
题目链接:http://codeforces.com/problemset/problem/1029/B 题目大意:从数组a中选出一些数组成数组b,要求 b[i+1]<=b[i]*2 . 一开始 ...
- Codeforces 940 E.Cashback (单调队列,dp)
Codeforces 940 E.Cashback 题意:一组数,要分为若干个区间,每个区间长度为ki(1<=ki<=n),并且对于每个区间删去前ki/c(向下取整)个小的数(即对区间升序 ...
随机推荐
- 在 Word 中的受支持的区域设置标识符的列表
这篇文章包含当前可用的区域设置 ID (LCID) 语言代码的列表. 概要 这篇文章包含当前可用的区域设置 ID (LCID) 语言代码的列表. 区域设置 ID (LCID): 由 Microso ...
- Diamond介绍
1. Diamond需求背景 我们的异步任务, 定时任务分布在多台服务器上处理, 所有有个配置文件去记录任务-服务器的分配关系.当动态的调整任务分配情况后,需要把工程重新启动, 这样频繁的操作对服务器 ...
- 倍福TwinCAT(贝福Beckhoff)基础教程7.1 TwinCAT 如何简单执行NC功能块 TC3
这一节我们介绍简单的NC运动(前面所讲的所有内容都是PLC编程和HMI的界面,算是基础知识),这里NC就是控制伺服电机的部分(当然还不是实际的NC轴,是虚拟轴,但是用到的函数都是一样,可以为后面的实际 ...
- Windows右击无新建文本文档怎么办
右击无新建文本文档2008-07-26 16:51 刚在网上找的,在运行项输入notepad,把下面的复制进去,然后保存为123.reg,双击导入. REGEDIT4 [HKEY_CLASSES_RO ...
- vue - config
build/build.js -> config 详细的config配置走向.
- eval(data)和eval("("+data+")")的区别
如果data是字符串,使用eval("("+data+")")可以将其转换为json对象,和JSON.parse的功能一样.如果data是json对象,使用ev ...
- iOS编程 手动忽略clang编译器警告
在iOS开发过程中, 我们可能会碰到一些系统方法弃用, weak.循环引用.不能运行之类的警告. 有代码洁癖的孩子们非常想消除他们, 今天就让我们来一次Fuck 警告.! 首先学会主要的语句 #pra ...
- asp.net 复习总结
1.asp.net页面上格式化时间是:<%# Eval("jsBianhao", "{0:yyyy/MM/dd}")%>
- IOS安装CocoaPods完整流程
作为一个底层系统大菜鸟,又搞过几年ios来说,安装一个CocoaPods是一件蛋痛的事~ 说懂又懂,说不懂又不懂. 由于安装过程比較复杂,步骤较多,而网上教程又比較零散,并且有一些是扯蛋的,所 ...
- YII2 学习
下载地址: http://www.yiiframework.com/download/ http://www.yiichina.com/download 直接选择basic模板下载即可 下载之后解压到 ...