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<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;
}
1 second
256 megabytes
standard input
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:
- 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.
Codeforces Round #257 (Div. 2/A)/Codeforces450A_Jzzhu and Children的更多相关文章
- 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 ...
- Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解
今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)
题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...
- Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)
主题链接:http://codeforces.com/problemset/problem/449/A ------------------------------------------------ ...
- Codeforces Round #257(Div. 2) B. Jzzhu and Sequences(矩阵高速幂)
题目链接:http://codeforces.com/problemset/problem/450/B B. Jzzhu and Sequences time limit per test 1 sec ...
- Codeforces Round #257 (Div. 2)
A - Jzzhu and Children 找到最大的ceil(ai/m)即可 #include <iostream> #include <cmath> using name ...
- Codeforces Round #257(Div.2) D Jzzhu and Cities --SPFA
题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路 ...
随机推荐
- uva 10192 Vacation(最长公共子)
uva 10192 Vacation The Problem You are planning to take some rest and to go out on vacation, but you ...
- TimesTen更改CacheGroup管理用户ORACLE结束和TT结束password【TimesTen操作和维修基地】
password管理一直操作的一部分的安全管理和维护.CacheGroup管理用户password虽然并不复杂变化.然而,这是用于生产,改不好比较easy导致失败.简介点击这里CacheGroup管理 ...
- 【Android开发经验】使用反射,得到的类的字段、方法、并实现了简单的调用
本文后推出Android的ICO框架做准备,所以,假设你想要一个最近的一项研究Android的ICO学生框架.你可以稍微看一下. 首先,简介一下Java里面的反射. JAVA反射机制是在执行状态中,对 ...
- 线性表实现简单vector
实现一个简单的vector Vector基于数组实现,可以复制并且其占用的内存可以自动回收(通过析构函数),可以调整Vector的大小,以及容量(容量的改变是通过为基本数组分配一个新的内存块,然后复制 ...
- 主攻ASP.NET MVC4.0之重生:ASP.NET MVC使用JSONP
原文:主攻ASP.NET MVC4.0之重生:ASP.NET MVC使用JSONP 原文地址 http://www.codeguru.com/csharp/.net/net_asp/using-jso ...
- 左右Map
Person p=new Person("黄雄"); Map map=new HashMap(); map.put("p", p); p.setName(&qu ...
- C++包括头文件<>和""差额
#include "book.h" #include<iostream.h> 在刚開始学习都会有这样的迷惑.有的程序用<>.有的却用"" ...
- iis6开户gzip 网站属性里面没有服务选项卡
请注意一点,是直接在名为“网站”的文件夹上面右键选择属性,不是去点下面建立的某一个网站.开户GZIP是整台服务器上面的虚拟主机都同时开启的,不对针某一个单独网站. 开启Gzip具体步骤: 1. 在 & ...
- BZOJ 2431 HAOI2009 在列的数目的顺序相反 递归
标题效果:乞讨1~n有都布置在物种的数目相反的顺序k计划数 订购f[i][j]对于前者i原子的反向排列的数j计划数 因此,我们将第一i插入的数1~i-1该装置 能生产0~i-1反向对 再就是 f[i] ...
- Java写程序猿专访String2
2.如何推理2一个字符串是否具有相同的字符 例如"aaaabbc"随着"abcbaaa" 2种思想 import java.lang.reflect.Array ...