A. Jzzhu and Children
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1to 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:

  1. Give m candies to the first child of the line.
  2. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home.
  3. 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 integersa1, a2, ..., an (1 ≤ ai ≤ 100).

Output

Output a single integer, representing the number of the last child.

Sample test(s)
input
5 2
1 3 1 4 2
output
4
input
6 4
1 1 2 2 3 3
output
6
Note

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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm> using namespace std; int main()
{
int n,m,i,j;
while(scanf("%d%d",&n,&m)!=EOF)
{
int str[],maxx=,st;
for(i=;i<n;i++)
{
scanf("%d",&str[i]);
if(maxx<str[i])
{
maxx=str[i];
}
}
st=maxx/m;
if(st*m<maxx)
{
st++;
}//printf("%d%d**",st,maxx);
for(i=;i<n;i++)
{
str[i]-=(st-)*m;//printf("%d**",str[i]);
}
int res=,cas;
for(i=;i<n;i++)
{
if(str[i]>)
{
//res=str[i];
cas=i;
}
}
printf("%d\n",cas+);
}
return ;
}

这是队列模拟的

 #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <queue> using namespace std; typedef struct stu
{
int id,m;
}stu;
stu str[]; int main()
{
int i,j,n,m,k,t; while(scanf("%d%d",&n,&m)!=EOF)
{
queue<stu >q; for(i=;i<n;i++)
{
scanf("%d",&str[i].m);
str[i].id=i+;
q.push(str[i]);
}
int tmp=;
while(!q.empty())
{
stu x=q.front();
q.pop();
if(x.m<=m)
{
tmp=x.id;
}
else
{
x.m-=m;
q.push(x);
}
}
printf("%d\n",tmp);
}
return ;
}

这题A题卡了我好久,主要因为数组模拟没有想到找最大的那个趟数来模拟

经验不足……

Codeforces Round #257 (Div. 2) A题的更多相关文章

  1. Codeforces Round #257 (Div. 2) D题:Jzzhu and Cities 删特殊边的最短路

    D. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

    E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解

    今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...

  4. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  5. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  6. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  7. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  8. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  9. Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)

    题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...

随机推荐

  1. Ubuntu 13.10 64位 无法 安装 ia32-libs 解决办法

    安装新立德软件包管理器:打开终端,输入以下命令:sudo apt-get install synaptic 打开新立德软件包管理器,选择“设置>软件库” 选择“其他软件 > 添加” 在AP ...

  2. Hadoop入门实践之从WordCount程序说起

    这段时间需要学习Hadoop了,以前一直听说Hadoop,但是从来没有研究过,这几天粗略看完了<Hadoop实战>这本书,对Hadoop编程有了大致的了解.接下来就是多看多写了.以Hado ...

  3. JSP页面跳转方式

    JSP页面跳转方式 1.利用按钮+javascript进行跳转 <input type="button" name="button2" value=&qu ...

  4. 如何修复损坏的MySQL数据表

    id=164 由于断电或非正常关机而导致MySQL数据库出现错误是非常常见的问题.有两种方法,一种方法使用mysql的check table和repair table 的sql语句,另一种方法是使用M ...

  5. NLog

    C# 使用NLog记录日志 C#第三方日志库Nlog NLog类库使用探索——详解配置 使用Nlog记录日志到数据库 NLog文章系列——系列文章目录以及简要介绍 NLog日志框架简写用法(write ...

  6. ExtJS的MessageBox总结

    自己写了个ExtJS的MsgBox的小模版,以后遇到需要使用提示的地方就拿过来改改,免得每次都重新写. /**MsgBox start**/ Ext.Msg.buttonText.yes = &quo ...

  7. Quartz2D简介及基本线条绘制

    * Quartz2D简介 1.什么是Quartz2D? 他是一个二维的绘图引擎,同时支持iOS和Mac系统 2.Quartz2D能完成的工作 画基本线条,绘制文字,图片,截图,自定义UIView. 3 ...

  8. js原型 prototype

    js中只有构造函数(所有函数)拥有prototype属性对象

  9. LeetCode----204. Count Primes(Java)

    package countPrimes204; /* * Description: * Count the number of prime numbers less than a non-negati ...

  10. Friendship

    Friendship Time Limit: 2000MS Memory Limit: 20000K Total Submissions: 9824 Accepted: 2720 Descriptio ...