(CF#257)A. Jzzhu and Children
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 2
1 3 1 4 2
4
6 4
1 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<cstring>
#include<algorithm>
using namespace std;
int a[110],num[110];
int n,m;
int main()
{
while(cin>>n>>m)
{
memset(num,0,sizeof(num));
for(int i=1;i<=n;i++)
{
cin>>a[i];
while(a[i]>0)
{
a[i]-=m;
num[i]++;
}
}
int k=1,maxn=0;
for(int i=1;i<=n;i++)
{
if(num[i]>=maxn)//此处注意是>=
{
k=i;
maxn=num[i];
}
}
cout<<k<<endl;
}
return 0;
}
(CF#257)A. Jzzhu and Children的更多相关文章
- (CF#257)B. Jzzhu and Sequences
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
- cf #257(Div.2) A. Jzzhu and Children
A. Jzzhu and Children time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)
题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children
A. Jzzhu and Children time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 450A - Jzzhu and Children 找规律也能够模拟
挺水的一道题.规律性非常强,在数组中找出最大的数max,用max/m计算出倍数t,然后再把数组中的书都减去t*m,之后就把数组从后遍历找出第一个大于零的即可了 #include<iostream ...
- [CodeForce 450A] Jzzhu and Children
题目链接:http://codeforces.com/problemset/problem/450/A /* * 计算一个人要是拿足够离开需要排多少次队,选排的次数多的那个人,如果两个人排的次数相同, ...
- CF450A 【Jzzhu and Children】
普通的模拟题这题用一个队列容器来模拟队列元素是pair类型的,first用来存每个小朋友想要的糖数,second用来存小朋友的序号,然后开始模拟,模拟出口是当队列迟到等于1时就输出当前队列里小朋友的序 ...
- Codeforces Round #257 (Div. 2/A)/Codeforces450A_Jzzhu and Children
解题报告 没什么好说的,大于m的往后面放,,,re了一次,,, #include <iostream> #include <cstdio> #include <cstri ...
- Codeforces Round #257 (Div. 2)
A - Jzzhu and Children 找到最大的ceil(ai/m)即可 #include <iostream> #include <cmath> using name ...
随机推荐
- centos 7 编译mod_security
yum install gcc-c++ flex bison yajl yajl-devel curl-devel curl GeoIP-devel doxygen zlib-devel libtoo ...
- OpenGL ES课程VI之纹理贴图(原文对照)
http://www.educity.cn/wenda/92368.html OpenGL ES教程VI之纹理贴图(原文对照) OpenGL ES Tutorial for Android – Par ...
- Centos查看文件夹大小
查看当前目录下文件夹大小 du -h --max-depth=1 查看整体情况 df -h
- 携程ELK
http://www.360doc.com/content/15/1203/00/26186435_517522477.shtml
- Error:scalac: Error: org.jetbrains.jps.incremental.scala.remote.ServerException
Error:scalac: Error: org.jetbrains.jps.incremental.scala.remote.ServerException reason:JDK与Scala的版本不 ...
- poj2406(后缀数组)
poj2406 题意 给出一个字符串,它是某个子串重复出现得到的,求子串最多出现的次数. 分析 后缀数组做的话得换上 DC3 算法. 那么子串的长度就是 \(len - height[rnk[0]]\ ...
- poj3254(状态压缩DP)
poj3254 题意 给出一个01矩阵,1表示当前这个位置可以放牛,要求放牛的方案保证牛不能左右或上下相邻,求方案数. 分析 dp[S][i]: 表示到 i 行时的状态S(用二进制数表示),那么状态转 ...
- 深入JS正则先行断言
这里是 Mastering Lookahead and Lookbehind 文章的简单翻译,这篇文章是在自己搜索问题的时候stackoverflow上回答问题的人推荐的,看完觉得写得很不错.这里的简 ...
- Java线程同步:synchronized锁住的是代码还是对象
所以我们在用synchronized关键字的时候,能缩小代码段的范围就尽量缩小,能在代码段上加同步就不要再整个方法上加同步.这叫减小锁的粒度,使代码更大程度的并发.原因是基于以上的思想,锁的代码段太长 ...
- [LOJ6279]数列分块入门 3
题目大意: 给你一个长度为$n(n\leq100000)$的序列$A$,支持进行以下两种操作: 1.将区间$[l,r]$中所有数加上$c$: 2.询问区间$[l,r]$中,严格小于$c$的最大数.思路 ...