码迷,mamicode.com
首页 > 其他好文 > 详细

[ An Ac a Day ^_^ ] CodeForces 677B Vanya and Food Processor 模拟

时间:2016-08-18 23:24:02      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:

题意:

你有一个榨汁机 还有n个土豆

榨汁机可以容纳h高的土豆 每秒可以榨k高的东西

问按顺序榨完土豆要多久

 

思路:

直接模拟

一开始以为是最短时间排了个序 后来发现多余了……

 

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<math.h>
 5 #include<string.h>
 6 #include<string>
 7 #include<map>
 8 #include<set>
 9 #include<vector>
10 #include<queue>
11 #define M(a,b) memset(a,b,sizeof(a))
12 using namespace std;
13 typedef long long ll;
14 int potato[100005];
15 int main(){
16     int n,h,k;
17     scanf("%d%d%d",&n,&h,&k);
18     for(int i=0;i<n;i++)
19         scanf("%d",&potato[i]);
20     ll ans=0,high=0;
21     for(int i=0;i<n;i++){
22         if(high+potato[i]<=h) high+=potato[i]; //能放下就放上去
23         else{  //放不下就打完了再放
24             high=potato[i]; 
25             ans++;
26         }
27         ans+=high/k;
28         high%=k;
29     }
30     if(high) ans++; //最后剩一点还要处理一下
31     printf("%I64d\n",ans);
32     return 0;
33 }
34 /*
35 
36 5 6 3
37 5 4 3 2 1
38 
39 5 6 3
40 5 5 5 5 5
41 
42 5 6 3
43 1 2 1 1 1
44 
45 */

 

[ An Ac a Day ^_^ ] CodeForces 677B Vanya and Food Processor 模拟

标签:

原文地址:http://www.cnblogs.com/general10/p/5785597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!