zoukankan      html  css  js  c++  java
  • [优先队列]Mining

    题目描述

    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

    优先队列模拟
    #include <iostream>
    #include<queue>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    typedef long long ll;
    using namespace std;
    
    int s,w,c,k,m;
    priority_queue<int,vector<int>,greater<int> > q;
    
    int main()
    {
        while(scanf("%d%d%d%d%d",&s,&w,&c,&k,&m)!=EOF){
            while(!q.empty()) q.pop();
    
            int num=10000/c;
            if(10000%c) num++;
    
            for(int i=1;i<=k;i++) q.push(i*m+s);
    
            int now=q.top();
            q.pop();
    
            q.push(now+w+2*s);
            int last=now;
    
            for(int i=2;i<=num;i++){
                if(q.top()-last<=w) now=last+w;
                else now=q.top();
                q.pop();
    
                q.push(now+w+2*s);
                last=now;
            }
            now+=w+s;
    
            printf("%d
    ",now);
        }
        return 0;
    }
    View Code
    转载请注明出处:https://www.cnblogs.com/lllxq/
  • 相关阅读:
    《Unix/Linux系统编程》第十二章学习笔记
    《Unix/Linux系统编程》第十四章学习笔记
    实验三电子公文传输系统1个人贡献
    js模版引擎(基于html模版和json数据的javascript交互)(第一讲)
    asp.net之反射
    JQuery 插件之Ajax Autocomplete(ajax自动完成)
    js模版引擎(基于html模版和json数据的javascript交互)(第二讲)完结篇
    在Sharepoint项目中究竟应该做哪类的开发?
    MVP Open day随想
    从瘦客户端到RIA
  • 原文地址:https://www.cnblogs.com/lllxq/p/10443033.html
Copyright © 2011-2022 走看看