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

时间:2022-12-14 20:23:29

解题报告

没什么好说的,大于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<n;i++)
{
cin>>num[i].cd;
num[i].x=i+1;
}
for(i=0;i<n;i++)
{
if(num[i].cd>m)
{
num[i].cd-=m;
num[n++]=num[i];
}
}
printf("%d\n",num[n-1].x);
return 0;
}
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 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.

Codeforces Round #257 (Div. 2/A)/Codeforces450A_Jzzhu and Children的更多相关文章

  1. Codeforces Round &num;257 &lpar;Div&period; 2&rpar; A&period; Jzzhu and Children(简单题)

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

  2. Codeforces Round &num;257 &lpar;Div&period; 2&rpar; A&period; Jzzhu and Children

    A. Jzzhu and Children time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. Codeforces Round &num;257 &lpar;Div&period; 1&rpar;A~C&lpar;DIV&period;2-C~E&rpar;题解

    今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...

  4. Codeforces Round &num;257 &lpar;Div&period; 1&rpar; C&period; Jzzhu and Apples &lpar;素数筛&rpar;

    题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...

  5. Codeforces Round &num;257 &lpar;Div&period; 2&rpar; B&period; Jzzhu and Sequences &lpar;矩阵快速幂&rpar;

    题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...

  6. Codeforces Round &num;257 &lpar;Div&period; 1&rpar;449A - Jzzhu and Chocolate&lpar;贪婪、数学&rpar;

    主题链接:http://codeforces.com/problemset/problem/449/A ------------------------------------------------ ...

  7. Codeforces Round &num;257&lpar;Div&period; 2&rpar; B&period; Jzzhu and Sequences(矩阵高速幂)

    题目链接:http://codeforces.com/problemset/problem/450/B B. Jzzhu and Sequences time limit per test 1 sec ...

  8. Codeforces Round &num;257 &lpar;Div&period; 2&rpar;

    A - Jzzhu and Children 找到最大的ceil(ai/m)即可 #include <iostream> #include <cmath> using name ...

  9. Codeforces Round &num;257&lpar;Div&period;2&rpar; D Jzzhu and Cities --SPFA

    题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路 ...

随机推荐

  1. 理解AUC

    本文主要讨论了auc的实际意义,并给出了auc的常规计算方法及其证明 转载请注明出处:http://www.cnblogs.com/van19/p/5494908.html 1 ROC曲线和auc 从 ...

  2. 在WebAPI使用Session

    最近在改写WebApp时要将以前用泛型处理例程写的Captcha 改成使用WebApi 来实作机制,在实作的过程中发现使用IRequiresSessionState session也无法使用(cont ...

  3. Discovering-论文

    Discovering Spatio-Temporal Causal Interactions in Traffic Data Streams data:real taxi trajectories ...

  4. Darkest page of my coding life

    The code i wrote a while ago recently caused a disaster and as I reviewed it I found it is the silli ...

  5. java笔记2之算术运算符

    1运算符是什么呢 对常量和变量进行操作的运算符 2运算符分为哪些 算术运算符(+,-,*,/), 赋值运算符 比较运算符 逻辑运算符 位运算符 三目运算符 3运算符 A 算术运算符的注意事项 (1)整 ...

  6. 自学nodejs系列

    好久没有搞nodejs了.nodejs也是更新的很快!!当初翻译的文档

  7. LintCode-数组划分

    题目描述: 给出一个整数数组nums和一个整数k.划分数组(即移动数组nums中的元素),使得: 所有小于k的元素移到左边 所有大于等于k的元素移到右边 返回数组划分的位置,即数组中第一个位置i,满足 ...

  8. MVC-04 视图(2)

    三.View如何从Aciton取得数据 从Action取得数据,在ASP.NET MVC可区分成两种方式,一种是“使用弱类型取得数据”,另一种则是“使用强类型取得数据”,两者的差别在于View页面最上 ...

  9. extract-text-webpack-plugin---webpack插件

    var ExtractTextPlugin=require('extract-text-webpack-plugin');//build使用 { test:/\.css$/, use:ExtractT ...

  10. BZOJ4555 HEOI2016&sol;TJOI2016求和(NTT&plus;斯特林数)

    S(i,j)=Σ(-1)j-k(1/j!)·C(j,k)·ki=Σ(-1)j-k·ki/k!/(j-k)!.原式=ΣΣ(-1)j-k·ki·2j·j!/k!/(j-k)! (i,j=0~n).可以发现 ...