题目链接:

B. Vanya and Food Processor

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed hand the processor smashes k centimeters of potato each second. If there are less than k centimeters remaining, than during this second processor smashes all the remaining potato.

Vanya has n pieces of potato, the height of the i-th piece is equal to ai. He puts them in the food processor one by one starting from the piece number 1 and finishing with piece number n. Formally, each second the following happens:

  1. If there is at least one piece of potato remaining, Vanya puts them in the processor one by one, until there is not enough space for the next piece.
  2. Processor smashes k centimeters of potato (or just everything that is inside).

Provided the information about the parameter of the food processor and the size of each potato in a row, compute how long will it take for all the potato to become smashed.

 
Input
 

The first line of the input contains integers nh and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ h ≤ 109) — the number of pieces of potato, the height of the food processor and the amount of potato being smashed each second, respectively.

The second line contains n integers ai (1 ≤ ai ≤ h) — the heights of the pieces.

 
Output
 

Print a single integer — the number of seconds required to smash all the potatoes following the process described in the problem statement.

 
Examples
 
input
5 6 3
5 4 3 2 1
output
5
input
5 6 3
5 5 5 5 5
output
10
input
5 6 3
1 2 1 1 1
output
2

题意:

有这么多高为a[i]的土豆,每次最多放h高度的土豆,超过了就不能放进去了,每秒削k高度的,问这些得用多长时间;

思路:

模拟削土豆的过程算一下时间就好了;

AC代码:
#include <bits/stdc++.h>
/*#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>
*/
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e9+;
const double PI=acos(-1.0);
const LL inf=1e10;
const int N=1e5+; int n,h,k;
int a[N];
int main()
{
read(n);read(h);read(k);
Riep(n)read(a[i]);
LL ans=,sum=;
Riep(n)
{
if(sum+a[i]>h)
{
if(sum%k==)ans=ans+sum/k;
else ans=ans+sum/k+;
ans=ans+a[i]/k;
sum=a[i]%k;
}
else
{
sum=sum+a[i];
ans=ans+sum/k;
sum=sum%k;
}
}
if(sum>)ans++;
print(ans);
return ;
}

codeforces 677B B. Vanya and Food Processor(模拟)的更多相关文章

  1. [ An Ac a Day ^_^ ] CodeForces 677B Vanya and Food Processor 模拟

    题意: 你有一个榨汁机 还有n个土豆 榨汁机可以容纳h高的土豆 每秒可以榨k高的东西 问按顺序榨完土豆要多久 思路: 直接模拟 一开始以为是最短时间排了个序 后来发现多余了…… #include< ...

  2. Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题

    B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...

  3. Codeforces Round #355 (Div. 2)-B. Vanya and Food Processor,纯考思路~~

    B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input s ...

  4. Codeforces 492B B. Vanya and Lanterns

    Codeforces  492B   B. Vanya and Lanterns 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  5. B. Vanya and Food Processor【转】

    B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. [Codeforces677B]Vanya and Food Processor(模拟,数学)

    题目链接:http://codeforces.com/contest/677/problem/B 题意:n个土豆,每个土豆高ai.现在有个加工机,最高能放h,每次能加工k.问需要多少次才能把土豆全加工 ...

  7. 暑假练习赛 006 A Vanya and Food Processor(模拟)

    Description Vanya smashes potato in a vertical food processor. At each moment of time the height of ...

  8. Codeforces Round #355 (Div. 2) B. Vanya and Food Processor

    菜菜菜!!!这么撒比的模拟题,听厂长在一边比比比了半天,自己想一想,然后纯模拟一下,中间过程检测一下,妥妥的就可以过. 题意:有N个东西要去搞碎,每个东西有一个高度,然后有一台机器支持里面可以达到的最 ...

  9. codeforces 677C C. Vanya and Label(组合数学+快速幂)

    题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input stan ...

随机推荐

  1. “非常PHP学习网”(www.veryphp.cn)一期上线

    制作“非常PHP学习网”花了国庆整个假期,其实是从电脑学习网(http://www.why100000.com,域名刚续费)改写盗版而来的. 起初主要修改界面布局和颜色花费了大量时间(好像制作网站80 ...

  2. C:函数

    函数 函数:都是实现一定的功能.具有特定功能的代码段.凡是由系统提供的函数就是库函数,自己写的函数就是自定义函数. 如何定义一个函数  :  函数类型修饰符  函数名 (函数参数)  {  函数语句 ...

  3. ActiveMQ简介与安装

    开源消息总线 支持JMS1.1和J2EE 1.4规范的 JMS Provider实现(持久化,XA消息,事务) 对Spring的支持,ActiveMQ可以很容易内嵌到使用Spring的系统里面去 支持 ...

  4. Mes首检确认统计的存储过程

    USE [ChiefmesNEW]GO/****** Object: StoredProcedure [dbo].[st_MES_RptInspectFirstCollect] Script Date ...

  5. (剑指Offer)面试题34:丑数

    题目: 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 思路: 1. ...

  6. Thinkphp的Volist标签

    Volist标签主要用于在模板中循环输出数据集或者多维数组. volist标签(循环输出数据) 闭合 非闭合标签 属性 name(必须):要输出的数据模板变量 id(必须):循环变量 offset(可 ...

  7. PostgreSQL中使用枚举类型

    https://wiki.postgresql.org/wiki/Enum 建立enum: pgsql=# CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy' ...

  8. Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题

    A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  9. Citrix 服务器虚拟化之二十八 XenApp6.5发布文档内容

    Citrix 服务器虚拟化之二十八  XenApp 6.5发布文档内容 XenApp可发布以下类型的资源向用户提供信息访问,这些资源可在服务器或桌面上虚拟化: 1)  服务器桌面:发布场中服务器的整个 ...

  10. 【JavaScript】AJAX总结(异步JavaScript和XML)

    AJAX介绍 通过 AJAX,你可以创建更好.更快以及更友好的 WEB 应用程序. AJAX 基于 JavaScript 和 JavaScript的XMLHttpRequest对象. AJAX 应用程 ...