A. Jzzhu and Children
来源:互联网 发布:淘宝iphone官换机骗局 编辑:程序博客网 时间:2024/05/16 20:28
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?
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 a single integer, representing the number of the last child.
5 21 3 1 4 2
4
6 41 1 2 2 3 3
6
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<algorithm>#include<cstdlib>#include<cstring>using namespace std;int main(){int n,m,max=0,i,j,a,b;scanf("%d%d",&n,&m);for(i=0;i<n;i++){scanf("%d",&a);b=a/m;if(a%m>0){b++;}if(max<=b){max=b;j=i;}}printf("%d\n",j+1);return 0;}
- A. Jzzhu and Children
- A. Jzzhu and Children
- codeforces-DIV2-A-Jzzhu and Children
- (CF#257)A. Jzzhu and Children
- Jzzhu and Children - CF 450A 水题
- Codeforces 450A Jzzhu and Children
- CodeForces 450-A. Jzzhu and Children
- Codeforces 450A Jzzhu and Children(水题)
- A. Jzzhu and Children (周赛4)
- 【CF 450A】 Jzzhu and Children
- codeforces 450A Jzzhu and Children
- Jzzhu and Children
- Jzzhu and Children
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children
- Codeforces Round #257 (Div. 2)1A Jzzhu and Children
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children
- cf #257(Div.2) A. Jzzhu and Children
- Codeforces Round #257 (Div. 2)A. Jzzhu and Children
- [线段树] POJ 3468 A Simple Problem with Integers
- Libgdx: android单机斗地主支持局域网wifi联网的网络模块核心代码
- 代理服务器proxy server
- 随机数的用法 (3种:arc4random() 、random()、CCRANDOM_0_1() )
- Windows下Subversion和Apache的安装及配置(一)
- A. Jzzhu and Children
- jquery的ajax实现登录名的校验
- Hadoop学习笔记之Hbase Shell不能删除问题解决
- Struts2的处理流程和对Action的管理方式
- 52单片机定时器2
- Android开发————LayoutInflater翻译
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第1章节--SharePoint 2013介绍 总结
- C++ Find Min and Max element in a BST
- VS2008+OpenGL环境下MyGUI编译