题意:

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

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

问按顺序榨完土豆要多久

思路:

直接模拟

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

 #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#define M(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
int potato[];
int main(){
int n,h,k;
scanf("%d%d%d",&n,&h,&k);
for(int i=;i<n;i++)
scanf("%d",&potato[i]);
ll ans=,high=;
for(int i=;i<n;i++){
if(high+potato[i]<=h) high+=potato[i]; //能放下就放上去
else{ //放不下就打完了再放
high=potato[i];
ans++;
}
ans+=high/k;
high%=k;
}
if(high) ans++; //最后剩一点还要处理一下
printf("%I64d\n",ans);
return ;
}
/* 5 6 3
5 4 3 2 1 5 6 3
5 5 5 5 5 5 6 3
1 2 1 1 1 */
05-02 14:22
查看更多