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. DataSnap 的连接事件顺序图

    无意看到这两幅图,虽然已经了解,还是转一份保留以备后用

  2. 【jQuery UI 1.8 The User Interface Library for jQuery】.学习笔记.9.Progressbar控件

    Progressbar控件用来显示任意进程的完成百分比. 默认安装启用 配置选项 控件暴露的事件API progressbar暴露的独一无二的方法 一些现实生活的例子 当前版本中,我们或系统必须明确进 ...

  3. Positional parameter are considered deprecated; use named parameters or JPA-style positional parameters instead.

    这行代码: List<Cat> catList =session.createQuery("from Cat p where p.name.first_name=?") ...

  4. HDU 2444:The Accomodation of Students(二分图判定+匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 题意:给出边,判断这个是否是一个二分图,并求最大匹配. 思路:先染色法求出是否是一个二分图,然后再匈牙利求 ...

  5. SQL Server 2005 日志文件过大处理

    由于安装的时候没有计划好空间,默认装在系统盘,而且又没有做自动备份.截断事务日志等,很快LDF文件就达到十几G,或者几十G ,此时就不得不处理了. 备份和计划就不说了,现在就说下怎么把它先删除吧: 1 ...

  6. 20145227 《Java程序设计》第1周学习总结

    20145227 <Java程序设计>第1周学习总结 教材学习内容总结 第一周学习Java首先了解了Java的历史,区分了JRE和JDK,并且学会了安装和配置环境.人机交互等基本知识,会编 ...

  7. 磕磕碰碰的Chrome之plugin开发

    前言 在Firefox下可用的npapi插件,在chrome下调用时遇到问题,于是尝试研究chrome下的ppapi插件,一路上真是磕磕碰碰,波折不断啊. 阶段一.复用npapi 尝试将npapi直接 ...

  8. DelegateCommand.cs

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  9. Codeforces Round #337 Alphabet Permutations

    E. Alphabet Permutations time limit per test:  1 second memory limit per test:  512 megabytes input: ...

  10. hdu1016 Prime Ring Problem

    dfs,用全局数组和变量保存并更新当前状态. 答案可以直接在搜索结束时打印,n为奇数时方案数为0. acm.hdu.edu.cn/showproblem.php?pid=1016 #include & ...