登录  /  注册

Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 12:01:27
原创
1067人浏览过

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


----------------------------------------------------------------------------------------------------------------------------------------------------------
登录后复制
登录后复制
欢迎光临天资小屋:http://user.qzone.qq.com/593830943/main
登录后复制
----------------------------------------------------------------------------------------------------------------------------------------------------------
登录后复制
登录后复制


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 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:

  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 integers a1,?a2,?...,?an (1?≤?ai?≤?100).

Output

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

Sample test(s)

input

5 21 3 1 4 2
登录后复制

output

input

6 41 1 2 2 3 3
登录后复制

output

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 <cstdio>#include <cmath>#include <cstring>#include <string>#include <iostream>#include <algorithm>using namespace std;struct child{	int x,num;}a[1000017];int main(){	int i, j, k;	int n, m;	while(scanf("%d%d",&amp;n,&amp;m)!=EOF)	{		memset(a,0,sizeof(a));		for(i = 1; i  m)			{				l++;				a[l].x = a[i].x-m;				a[l].num = a[i].num;				a[i].x = 0;			}		}		printf("%d\n",a[i-1].num);	}	return 0;}</algorithm></iostream></string></cstring></cmath></cstdio>
登录后复制



 

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号