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 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
Sample Output
5
Hint
题意
有一个榨汁机,有n个苹果,一个一个的扔进去,然后榨汁机可以一次性榨掉最后的h高,然后这个榨汁机可以每秒钟榨k米,问你最少需要多少时间
题解:
水题,小于h的肯定都一起扔进去,然后剩下的就是能扔就扔
中间过程用数学去计算就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n;
long long h,k,a[maxn];
int main()
{
scanf("%d%lld%lld",&n,&h,&k);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
long long now = 0,ans = 0;
for(int i=1;i<=n;i++)
{
if(now+a[i]<=h)now+=a[i];
else{
now=a[i];
ans++;
}
long long t = now/k;
ans+=t;
now-=t*k;
}
if(now)ans++;
cout<<ans<<endl;
}
Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题的更多相关文章
- 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 ...
- Codeforces Round #355 (Div. 2) B. Vanya and Food Processor
菜菜菜!!!这么撒比的模拟题,听厂长在一边比比比了半天,自己想一想,然后纯模拟一下,中间过程检测一下,妥妥的就可以过. 题意:有N个东西要去搞碎,每个东西有一个高度,然后有一台机器支持里面可以达到的最 ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题
C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...
- Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题
A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题
A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...
- Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题
A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure 分治暴力
D. Vanya and Treasure 题目连接: http://www.codeforces.com/contest/677/problem/D Description Vanya is in ...
随机推荐
- 最短路径—Floyd算法
Floyd算法 所有顶点对之间的最短路径问题是:对于给定的有向网络G=(V,E),要对G中任意两个顶点v,w(v不等于w),找出v到w的最短路径.当然我们可以n次执行DIJKSTRA算法,用FLOYD ...
- MVVM设计模式的事件绑定
为什么要事件绑定 这个问题其实是很好理解的,因为事件是丰富多样的,单纯的命令绑定远不能覆盖所有的事件.例如Button的命令绑定能够解决Click事件的需求,但Button的MouseEnter.窗体 ...
- 09 Command Documentation 命令文档
Command Documentation 命令文档 There is a suite of programs to build and process Go source code. Inste ...
- 如何从TFS(Visual Studio Team Foundation Server)映射下载本地文件夹
1.连接tfs项目 首先打开vs2017 ——>工具栏 中的 团队——> 选择团队的管理链接 2.选择管理工作区 显示管理工作区的弹窗,点击 编辑 显示弹窗,选择本地文件夹(即要保存 ...
- 使用vs2015编辑c++模板程序报错2019
笔者这几天在熟悉vs2015工具编辑c++,(从前用的都是vc++6.0).发现还真是不容易使用,简单的一个小程序会报错一大堆你看不懂的问题.现将我发现的重要的一个问题呈现给大家. 在使用类模板设计对 ...
- 使用dos命令创建多模块Maven项目
好吧,咱们接着上一篇博客继续用另一种方式来创建Maven项目.不过在创建之前我们应该先熟悉一些相关dos命令. 创建web项目命令: mvn archetype:generate -DgroupId= ...
- Centos之关机和重启命令
shutdown命令 shutdown [选项] 时间 -c:取消前一个关机命令 -h:关机 -r:重启 [root@localhost ~]# date 2017年 06月 21日 星期三 15:4 ...
- SQL Server中删除表中重复数据
方法一:利用游标,但要注意主字段或标识列 declare @max integer,@id integer open cur_rows fetch cur_rows into @id,@max beg ...
- Linux学习笔记:ls和ll命令
list显示当前目录中的文件名字,不加参数时显示除隐藏文件外的所有文件及目录的名字. ll 等同于 ls -l-r 对目录反向排序(按字母)-t 以时间排序-u 以文件上次被访问的时间排序-x 按列输 ...
- 编程六月定律 | 外刊IT评论网
编程六月定律 上周,我被迫对一个很老的项目做一些修改.麻烦是,当开始着手时,我真的记不清这个项目究竟有多老了. 这实际上是我使用Codeigniter实现的第一个MVC项目.打开项目文件后,很多东西都 ...