zoj 1200 Mining 优先队列模拟

11043: Mining

时间限制: 1 Sec  内存限制: 128 MB
提交: 147  解决: 41
[提交] [状态] [讨论版] [命题人:admin]

题目描述

A mining base needs to build some robots to collect at least 10000 units of resource. Each robot will start from the base, reach the diggings in S minutes, work for W minutes, and then take C units of resource back to the base in S minutes.
  To speed up this procedure, K robots will be built at the base. It takes M minutes to produce one robot. A robot will be set to start working immediately after it is built, and producing the next robot will be on line right after. This procedure continues untill all the robots are built.
  Due to the limitation of the mining equipments, there can be only one robot digging at the working area. That is, it is only after the currently working robot finishes its collecting work and starts getting back to the base that the next robot can work at the diggings.
  Now it is your job to write a program to simulate this procedure, and find out how many minutes it will take to collect at least 10000 units of resource. 

 

输入

There are several lines of input. Each line contains a test case which consists of 5 integers, namely S, W, C, K, and M. 

 

 

输出

For each test case, you are asked to output an integer t, which is the number of minutes taken to collect at least 10000 units of resource. 

 

 

样例输入

复制样例数据

10 20 10 1 5

样例输出

40005

题意:需要建造机器人进行挖矿采集10000的资源,每个机器人从出发到开始工作需要S时间,挖矿需要W分钟,可以带回C数量的资源,返回还是需要S时间,建造K个机器人,一个机器人需要M分钟。

每个机器人需要等待上一个机器人挖完才可以进去,求最小时间,考虑优先队列(从小到大)

每次推进去机器人到达矿的时间,记录次数

开始先计算出需要多少次挖掘,之后比较次数即可

代码:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e2 + 100;
const int mod = 1e9 + 7;

priority_queue<int, vector<int>, greater<int> > q;

int main() {
    int s, w, c, k, m;
    while (cin >> s >> w >> c >> k >> m) {
        while (!q.empty()) q.pop();
        int cnt = 9999 / c + 1;
        k = min(cnt, k); //若机器人比需要次数多可以舍去
        for (int i = 1; i <= k; i++) {
            q.push(m * i + s);
        }
        int noww = -1, num = 0;
        while (!q.empty()) {
            int ti = q.top();
            q.pop();
            if (ti < noww) ti = noww;
            noww = ti + w;
            num++;
            if (num == cnt) {
                printf("%d\n", ti + w + s);
                break;
            }
            q.push(ti + w + s + s);
        }
    }
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值