暑假练习赛 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 ...
随机推荐
- 翻译 | 使用A-Frame打造WebVR版《我的世界》
原文地址:Minecraft in WebVR with HTML Using A-Frame 原文作者:Kevin Ngo 译者:Felix 校对:阿希 我是 Kevin Ngo,一名就职于 Moz ...
- C/C++ 进程通讯(命名管道)
服务端代码: // pipe_server.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> ...
- sdk&jdk&jre
1. jre and jdkJRE(Java Runtime Enviroment)是Java的运行环境.面向Java程序的使用者,而不是开发者.如果你仅下载并安装了JRE,那么你的系统只能运行Jav ...
- 6656 Watching the Kangaroo
6656 Watching the KangarooDay by day number of Kangaroos is decreasing just liketiger, whale or lion ...
- 通过JQuery实现Ajax代码
今天早上遇到了这个问题,结果我写的顺序是惨不忍睹啊,所有现在留个模版以示标准. $(function(){ $.ajax({ url : "Servlet", //传地址 type ...
- PHP连接SQL Server数据库
服务环境:apache2.2 + PHP5.2 + Sql Server 2008 R2 一.所需库和工具1.SQLSRV20.EXE (php5.2版本对应的的Sql Server扩展库)注释:ph ...
- mysqldumpslow -- 分析慢查询日志
格式:mysqldumpslow [选项] 慢查询日志路径 选项: -s 排序方式,可选值有c(记录次数).t(查询时间).l(锁定时间).r(返回记录).a(平均) -t 显示的记录数 - ...
- Python自学笔记-递归函数(来自廖雪峰的官网Python3)
感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. 递归函数 ...
- python爬取煎蛋网图片
``` py2版本: #-*- coding:utf-8 -*-#from __future__ import unicode_literimport urllib,urllib2,timeimpor ...
- ZOJ-3933-Team Formation【二分图最佳匹配】【KM】
http://blog.csdn.net/loy_184548/article/details/51154195 一开始对不同组合得不同分数(mm1,mg2,gg3),想用sap来写,但是保证了 ...