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(向下取整)个小的数(即对区间升序 ...
随机推荐
- [Functional Programming Monad] Map And Evaluate State With A Stateful Monad
We explore our first stateful transaction, by devising a means to echo our state value into the resu ...
- 【DP】【单调队列】【NOI2005】瑰丽华尔兹
340. [NOI2005] 瑰丽华尔兹 ★★★ 输入文件:adv1900.in 输出文件:adv1900.out 简单对照 时间限制:1 s 内存限制:128 MB [任务描写叙述] 你跳过华尔兹吗 ...
- 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何查看错误代码
一般模块出错会在Error中显示为TRUE,同时ErrorID中会有一个错误代码,下图所示就是出错之后的效果 在变量表中也可以看到,右击转成16进制查看 由于是NC模块出错,所以可以再NC的E ...
- 【CI】系列三.宿主机KVM配置及vdi与vmdk格式转换等
前提:宿主机需要支持虚拟化,如果未打开,则需要重启机器,在bois中打开该项: Ubuntu 及 KVM 相关主要参考官方 https://wiki.ubuntu.com/kvm 另外也可参考该页面: ...
- Odoo8模块中增加延时自动消失的提示
在odoo中,如果必要栏位没有值,在保存时右上角会有如下图的提示,该提示会延时并自动关闭. 有网友问如何在自己的模块中增加这样的提示,以方便用户在操作时,能提示一些必要的信息.下面例出大致的步骤以供参 ...
- 【Java】Java_02环境配置
JDK是什么?JRE是什么?JDK和JRE的区别? Java Runtime Environment (JRE) 包含: Java虚拟机.库函数.运行Java应用程序和Applet所必须文件 Java ...
- UE4 场景展示Demo
使用到的level blueprint如下:
- 用JDOM读取XML文件
用JDOM读取XML文件需先用org.jdom.input.SAXBuilder对象的build()方法创建Document对象,然后用Document类.Element类等的方法读取所需的内容.IB ...
- Kubernetes使用prometheus+grafana做一个简单的监控方案
前言 本文介绍在k8s集群中使用node-exporter.prometheus.grafana对集群进行监控.其实现原理有点类似ELK.EFK组合.node-exporter组件负责收集节点上的me ...
- Android开发SDK接入机智云,智能家居实现APP远程控制多设备
代码地址如下:http://www.demodashi.com/demo/12847.html 一.前言. 此框架只用了一周星期做了出来,因为对机智云的框架比较熟悉了 !期间SDK初始化出了问题,去咨 ...