codeforces 677B B. Vanya and Food Processor(模拟)
2016-06-02 09:35
134 查看
题目链接:[b]B. Vanya and Food Processor[/b]time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputVanya 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: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.InputThe 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.OutputPrint a single integer — the number of seconds required to smash all the potatoes following the process described in the problem statement.Examplesinput
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputVanya 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: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.InputThe 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.OutputPrint a single integer — the number of seconds required to smash all the potatoes following the process described in the problem statement.Examplesinput
5 6 3 5 4 3 2 1output
5input
5 6 3 5 5 5 5 5output
10input
5 6 3 1 2 1 1 1output
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<'0'||CH>'9';F= CH=='-',CH=getchar()); for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar()); F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) { if(!p) { puts("0"); return; } while(p) stk[++ tp] = p%10, p/=10; while(tp) putchar(stk[tp--] + '0'); putchar('\n'); } const LL mod=1e9+7; const double PI=acos(-1.0); const LL inf=1e10; const int N=1e5+15; int n,h,k; int a ; int main() { read(n);read(h);read(k); Riep(n)read(a[i]); LL ans=0,sum=0; Riep(n) { if(sum+a[i]>h) { if(sum%k==0)ans=ans+sum/k; else ans=ans+sum/k+1; ans=ans+a[i]/k; sum=a[i]%k; } else { sum=sum+a[i]; ans=ans+sum/k; sum=sum%k; } } if(sum>0)ans++; print(ans); return 0; }
相关文章推荐
- 关于线性模型你可能还不知道的二三事(一、样本)
- LeetCode题解——Intervals相关题总结
- 前端
- http下载 文件 txt或者jpg图片
- Java中的基础----多线程的实现
- CISCO防火墙ASA发现DDOS***及应急预案
- SQL Server 2016新特性:动态数据屏蔽(Dynamic Data Masking)
- Python 进阶 —— 重访 tuple
- 自定义ContentProvider及使用ContentResolver解析详细步骤
- 2016 年你应该学习的语言和框架
- PullToRefresh 使用详解
- C# 设计模式系列教程-原型模式
- TextView属性大全+单行显示长文本
- MEAN栈开发
- 课堂练习(卖书问题)
- 【代码】C#生成指定长度的随机数方法
- 薄荷Toolbar(ActionBar)的适配方案
- 入门指南
- ajax、Spring提交表格的时候出现中文乱码
- 【51CTO学院三周年】桃李不言,下自成蹊