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

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

水题,就不多说了,贴代码吧0.0

#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

时间: 2024-07-31 19:31:10

(CF#257)A. Jzzhu and Children的相关文章

(CF#257)C. Jzzhu and Chocolate

Jzzhu has a big rectangular chocolate bar that consists of n?×?m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edg

(CF#257)B. Jzzhu and Sequences

Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo 1000000007 (109?+?7). Input The first line contains two integers x and y (|x|,?|y|?≤?109). The second line contains a single i

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

题目链接:http://codeforces.com/problemset/problem/450/A ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

450A - Jzzhu and Children 找规律也可以模拟

挺水的一道题,规律性很强,在数组中找出最大的数max,用max/m计算出倍数t,然后再把数组中的书都减去t*m,之后就把数组从后遍历找出第一个大于零的就行了 #include<iostream> #include<stdio.h> using namespace std; int main(){ // freopen("in.txt","r",stdin); int a[105],n,m; while(~scanf("%d%d&qu

Codeforces Round #257 (Div. 2/A)/Codeforces450A_Jzzhu and Children

解题报告 没什么好说的,大于m的往后面放,,,re了一次,,, #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; struct node { int x,cd; }num[1000000]; int main() { int n,m,c; cin>>n>>m; int i; for(i=0;i&l

Codeforces Round #257 (Div. 2)

A.Jzzhu and Children 计算每个人会出现的轮次数,取最后一个且轮次数最大的,注意是用a[i]-1 % m,倒着扫一遍就行了 #include <iostream> #include <cstdio> #include <cstdlib> using namespace std; const int maxn = 100+10; int n, m; int a[maxn]; int main() { #ifdef LOCAL freopen("

Codeforces Round #257 (Div. 2) A/B/C/D

前三题早就写好了,一直在纠结D A. Jzzhu and Children 题意:就是简单的模拟,给排成一队的孩子分发糖果,每个孩子有至少要得到的糖果数. 然后每次给队头的孩子分发m个糖果,如果他已经得到了足够的糖果(大于等于他想得到的 最少糖果数)那么他就出队,否则他就去队尾.问最后一个孩子的编号. 算法:队列模拟,水题~ #include<cstdio> #include<iostream> #include<cstring> #include<queue&g

Codeforces Round #257 (Div. 2) 题解

Problem A 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 chi

跟着xiaoxin巨巨做cf

cf 385 C. Bear and Prime Numbers 题目大意:有一个数列{xi},每次给出一个询问[l, r],即问 S(l ,r)是l和r之间的素数,f(p)表示数列{xi}中整除p的个数 思路:筛法,显然xi的顺序是无所谓的,我们把它记录下来,然后做筛法,如果一个素数筛合数的过程中遇到一个数的话显然得记到这个素数的头上,然后再把这样得到的表求一个sum就行 1 #include<iostream> 2 #include<cstdio> 3 #define maxn