暑假练习赛 006 A Vanya and Food Processor(模拟)
Description
Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and 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:
- 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.
- 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 n, h 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.
Sample Input
5 6 3
5 4 3 2 1
5
5 6 3
5 5 5 5 5
10
5 6 3
1 2 1 1 1
2
Sample Output
Hint
Consider the first sample.
- First Vanya puts the piece of potato of height 5 into processor. At the end of the second there is only amount of height 2 remaining inside.
- Now Vanya puts the piece of potato of height 4. At the end of the second there is amount of height 3 remaining.
- Vanya puts the piece of height 3 inside and again there are only 3 centimeters remaining at the end of this second.
- Vanya finally puts the pieces of height 2 and 1 inside. At the end of the second the height of potato in the processor is equal to 3.
- During this second processor finally smashes all the remaining potato and the process finishes.
In the second sample, Vanya puts the piece of height 5 inside and waits for 2 seconds while it is completely smashed. Then he repeats the same process for 4 other pieces. The total time is equal to 2·5 = 10 seconds.
In the third sample, Vanya simply puts all the potato inside the processor and waits 2 seconds.
/*
切土豆机,每秒切k,最多能盛h
都是泪,连for循环里的i都得用long long
*/
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#define INF 0x3f3f3f3f
#define N 100010
using namespace std;
/*bool comp(long long a,long long b)
{
return a>b;
}*/
int main()
{
//freopen("in.txt","r",stdin);
long long n,h,k,cur[N];
scanf("%lld%lld%lld",&n,&h,&k);
//cout<<n<<" "<<h<<" "<<k<<endl;
bool flag=false;
for(long long i=;i<n;i++)
{
scanf("%lld",&cur[i]);
if(cur[i]>)
flag=true;
}
if(!flag)
{
printf("0\n");
return ;
}
long long cut=;
long long sum=;//表示当前机器中有多少土豆
//sort(cur,cur+n);
//for(long long i=0;i<n;i++)
// cout<<cur[i]<<" ";
//cout<<endl;
for(long long i=;i<n;i++)
{
if(sum+cur[i]>h)
{
sum=cur[i];
cut++;
}
else
sum+=cur[i];
cut+=sum/k;
sum%=k;//每一秒都少了k;
}
//cout<<"sum="<<sum<<endl;
if(sum>)
cut++;
//cout<<sum<<endl;
printf("%lld\n",cut);
//cout<<endl;S
return ;
}
暑假练习赛 006 A Vanya and Food Processor(模拟)的更多相关文章
- 暑假练习赛 006 E Vanya and Label(数学)
Vanya and LabelCrawling in process... Crawling failed Time Limit:1000MS Memory Limit:262144KB ...
- codeforces 677B B. Vanya and Food Processor(模拟)
题目链接: B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes i ...
- 暑假练习赛 006 B Bear and Prime 100
Bear and Prime 100Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:262144KB ...
- [ An Ac a Day ^_^ ] CodeForces 677B Vanya and Food Processor 模拟
题意: 你有一个榨汁机 还有n个土豆 榨汁机可以容纳h高的土豆 每秒可以榨k高的东西 问按顺序榨完土豆要多久 思路: 直接模拟 一开始以为是最短时间排了个序 后来发现多余了…… #include< ...
- 暑假练习赛 004 E Joint Stacks(优先队列模拟)
Joint StacksCrawling in process... Crawling failed Time Limit:4000MS Memory Limit:65536KB 64 ...
- 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 ...
- B. Vanya and Food Processor【转】
B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input s ...
- 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 ...
- 暑假练习赛 003 F Mishka and trip
F - Mishka and trip Sample Output Hint In the first sample test: In Peter's first test, there's on ...
随机推荐
- ajax 发送json 后台接收 遍历保存进数据库
前台怎么拿参数的我就不管了我也不会 反正用这个ajax没错 ajax 代码 一定要写明http请求类型 { contentType:"application/x-www-form-ur ...
- Spring Boot 学习之项目构建
最近做了外包,都是工程专业术语,前期熟悉项目看文档看的挺累的,闲暇时间自己学习一下Spring Cloud,找点乐趣. 就有了下面的小项目. 本项目是一个Spring boot项目. 一.nginx做 ...
- MySQL所学所思所想
MySQL更改线上配置方案思想:原则上,需要备机.备份工作准备到位,有参数调优配置方案.有配置回退方案.有应急切换备机方案.以上方案评审无问题,然后可以和客户约定实施的时间.服务中断时间,先向客户侧申 ...
- Invoke 用法
转自:http://blog.sina.com.cn/s/blog_5a6f39cf0100s23x.html 在多线程编程中,我们经常要在工作线程中去更新界面显示,而在多线程中直接调用界面控件的方法 ...
- Scaffolding Template on Asp.Net Core Razor Page
Scaffolding Template Intro 我们知道在Asp.Net MVC中,如果你使用的EF的DBContext的话,你可以在vs中通过右键解决方案-添加控制器-添加包含视图的控制器,然 ...
- 基于maven创建和部署Webx项目
1.准备工作 下载 Webx Maven 项目的目录结构Artifact插件. archetype-webx-quickstart-1.0.tar.gz插件:http://central.maven. ...
- Cow Exhibition 变种背包
Cow Exhibition Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- Ubuntu16.04下安装redis
Ubuntu16.04下安装redis 保证网络畅通,选定好下载工作路径,执行以下命令下载redis-3.2.6: sudo wget http://download.redis.io/release ...
- MVVM 模版里的控件怎样触发命令
public class BaseWindow : Window { public BaseWindow() { InitializeStyle(); //给样式的控件加载事件 this.Loaded ...
- cocos2dx - 在MFC中使用cocos2dx
本节主要讲一下如何在MFC窗口中使用cocos2dx 在做比较复杂的游戏,有时需要通过一些工具来编辑生成关卡或者特效,技能等的配置文件.为了方便配置,需要可以通过修改参数直观得到显示的效果.这就需要将 ...