Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)
题目链接:http://codeforces.com/problemset/problem/450/A
----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋:http://user.qzone.qq.com/593830943/main
----------------------------------------------------------------------------------------------------------------------------------------------------------
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.
代码例如以下:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std; struct child
{
int x,num;
}a[1000017];
int main()
{
int i, j, k;
int n, m;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(a,0,sizeof(a));
for(i = 1; i <= n; i++)
{
scanf("%d",&a[i].x);
a[i].num = i;
}
int l = n;
for(i = 1; a[i].x != 0; i++)
{
if(a[i].x <= m)
{
a[i].x = 0;
continue;
}
if(a[i].x > m)
{
l++;
a[l].x = a[i].x-m;
a[l].num = a[i].num;
a[i].x = 0;
}
}
printf("%d\n",a[i-1].num);
}
return 0;
}
Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)的更多相关文章
- 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. 2/A)/Codeforces450A_Jzzhu and Children
解题报告 没什么好说的,大于m的往后面放,,,re了一次,,, #include <iostream> #include <cstdio> #include <cstri ...
- 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. 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. 2) B Jzzhu and Sequences
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
- Codeforces Round #257 (Div. 1) D - Jzzhu and Numbers 容斥原理 + SOS dp
D - Jzzhu and Numbers 这个容斥没想出来... 我好菜啊.. f[ S ] 表示若干个数 & 的值 & S == S得 方案数, 然后用这个去容斥. 求f[ S ] ...
- Codeforces Round #257 (Div. 2) C. Jzzhu and Chocolate
C. Jzzhu and Chocolate time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- c++学习笔记---02---从一个小程序说起
从一个小程序说起 这一讲的主要目的是帮助大家在C语言的背景知识上与C++建立联系. 问题探索 问题:对一个整型数组求和. 要求:定义一个存储着 n 个元素的数组,要求用C语言完成这个任务. 赶紧的:大 ...
- JS基础 复习: Javascript的书写位置
爱创课堂JS基础 复习: Javascript的书写位置复习 js书写位置:body标签的最底部.实际工作中使用书写在head标签内一对script标签里.alert()弹出框.console.log ...
- 开发环境MAPLAB下使用仿真器ICD2程序下载流程
程序下载流程 一. 连接示意图 二. 下载步骤 1.目标板电源断开 2.将仿真器下载端口与电路板JTAG端口有效连接 3.启动MPLAB软件 4.点击MAPLAB软件上方Programme ...
- jquery操作html小技巧
1.隐藏table整列 $("#tableID tr").find('td:eq(N)').hide();
- 【1】hadoop搭建常用的Linux命令收集
大数据学习第一步:Linux入门学习所需要的命令(非基础却常用) chmod u+x /filepath/../filename : u.g.o表示三个不同组,r.w.x表示可读可写可执行,+.-表示 ...
- 异步获取CMD命令行输出内容
当控制台命令使用process.Start(); 后可以直接显示输出内容,当然它是异步显示的不用等程序结束.代码如下: using System;using System.Collections.Ge ...
- [转载] Comet:基于 HTTP 长连接的“服务器推”技术
转载自http://www.ibm.com/developerworks/cn/web/wa-lo-comet/ “服务器推”技术的应用 传统模式的 Web 系统以客户端发出请求.服务器端响应的方式工 ...
- 基于BroadReceiver实现获取短信内容
我朋友拜托我做一个能实现向指定号码发短信获取动态密码的一个小app,中间用到了基于监听系统通知的BroadReceiver 来实现获取有新短信并且获取新短信的内容.下面就是这个小app的实现监听部分的 ...
- struts2的简单执行过程
struts2是最近刚学的一个框架,想通过写篇文章来加深下印象,这也是本篇博文产生的由来,下面进入正题 Struts2本身是一个挺简单的框架,我们通过写一个登陆的过程来具体描述下其执行过程 1.首先我 ...
- canvas图表(4) - 散点图
原文地址:canvas图表(4) - 散点图 今天开始完成散点图,做完这一节,我的canvas图表系列就算是完成了,毕竟平时最频繁用到的就是这几类图表了:柱状,折线,饼图,散点.经过编写canvas图 ...
