题目链接
题目大意:一个采矿基地需要建造一些机器人来收集至少10000单位的资源。每个机器人从基地出发,在S分钟内到达挖掘地点,工作W分钟,然后在S分钟内将C个单位的资源运回基地。
为了加快这一进程,将在基地建造K个机器人。制造一个机器人需要M分钟。机器人建成后将立即开始工作,生产下一个机器人后将立即上线。这个过程一直持续到所有的机器人都被制造出来。
由于采矿设备的限制,只能有一个机器人在工作区域进行挖掘。也就是说,只有当当前工作的机器人完成采集工作并开始返回基地后,下一个机器人才能在挖掘现场工作。
现在您的工作是编写一个程序来模拟这个过程,并找出收集至少10,000个资源单元需要多少分钟。
解题思路:计算采集至少10000个资源单位需要机器人工作的总次数n,利用优先队列,首先把每个机器人第一次到达工作区域需要的时间放入到优先队列中,然后取出花费时间最少的机器人,让它进行采集工作,并把它下一次到达工作区域需要的时间放入到优先队列中,如此重复进行n次即可。
AC代码:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <queue> #include <stack> #include <vector> #include <map> #include <set> using namespace std; #define io ios::sync_with_stdio(0),cin.tie(0) #define ms(arr) memset(arr,0,sizeof(arr)) #define mc(a,b) memcpy(a,b,sizeof(b)) #define inf 0x3f3f3f #define fin freopen("in.txt", "r", stdin) #define fout freopen("out.txt", "w", stdout) typedef long long ll; typedef unsigned long long ULL; const int mod=1e9+7; const int N=1e5+7; priority_queue <int, vector<int>, greater<int> > q; int s,w,c,k,m; int main() { while(scanf("%d%d%d%d%d",&s,&w,&c,&k,&m)!=EOF) { while(!q.empty()) { q.pop(); } int n=9999/c+1;//需要的机器人工作的总次数 for(int i=1;i<=k;i++) q.push(i*m+s);//生产的第i个机器人到达工作区域需要的时间 int time=q.top();//time表示当前一个机器人进入工作区域的时间 for(int i=1;i<n;i++) { q.pop(); q.push(time+s*2+w); if(q.top()-time<w) time+=w; else time=q.top(); } time+=s+w; printf("%dn",time); } return 0; }
最后
以上就是冷酷小熊猫最近收集整理的关于ZOJ Problem Set - 1200 Mining 【优先队列】的全部内容,更多相关ZOJ内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复