您的位置:首页 > 其它

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
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<'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;
}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: