zoukankan      html  css  js  c++  java
  • Job!Job!Job!

    描述

    Foreverlin is working in a company. In order to make boss happier, he must work as hard as possible, there are n projects on the todolist. Now is time 1, after time m ,foreverlin has to go back to the school .each project has two properties , the finally completion time and the value you can make if you finish this project . At every unit of time ,he can choose a project to finish . However, he can only change one project to do in one unit time, that means in one unit time ,he can choose a project to do and finish in this unit time. As the best friend of him ,can you help him to find out how to arrange these projects so that he can make the biggest values. 

    输入

    There are several test cases, in each test case, there are two numbers n,m(1<=n<=100000,1<=m<=1000000) . The next n lines each contains two number D[i],V[i] (1 <= D[i] <= 100000,1<=V[i]<=10000) (1<=i<=n ,D[i] means if you choose to do project i ,you can not do this after time D[i],V[i] means the value of project i ) The input will finish with the end of file.

    输出

    For each the case ,ouput a number means the biggest values.

    样例输入

    4 10
    1 8
    1 3
    2 10
    5 12

    样例输出

    30

    题目大意:在m分钟内最多选取m件任务,使得总价值最大(1-m每分钟可以选择一件任务,但是选取到的任务必须小于等于截止时间)

    解题思路:优先队列+贪心   从m分钟到第1分钟,每分钟加入第几分钟的所有任务,并且从优先队列中取出最大一个进行求和。

    #include <bits/stdc++.h>
    using namespace std;
    #define N 100000
    #define ll __int64
    vector <int> vec[N+5];
    int main()
    {
        int n,m,k;
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            priority_queue <int> qu;
            for(int i=1;i<=100000;i++) vec[i].clear();
            for(int i=1;i<=n;i++)
            {
                int aa,bb;
                scanf("%d%d",&aa,&bb);
                if(aa>m) aa=m; //超出最大时间,当做最大时间处理 
                vec[aa].push_back(bb);
            }
            ll sum=0;
            for(int i=m;i>=1;i--)
            {
                for(int j=0;j<vec[i].size();j++) qu.push(vec[i][j]);
                if(!qu.empty())
                {
                    sum+=qu.top();
                    qu.pop();
                }
            }
            printf("%I64d
    ",sum);
        }
    }
  • 相关阅读:
    为什么我们从Yarn切换到pnpm
    🔑 最佳密码长度是多少?
    vue + ArcGIS 地图应用系列二:加载地图
    vue + ArcGIS 地图应用系列一:arcgis api本地部署(开发环境)
    玩转 GitHub 的几个小技巧
    在 Array.some 中正确使用 async
    如何正确的在 Array.map 使用 async
    一道关于JavaScript 代码执行顺序的面试题解析
    Git 常用命令及应用这一篇就够了(新手向)
    VUE 子组件向父组件传值 , 并且触发父组件方法(函数)
  • 原文地址:https://www.cnblogs.com/ww123/p/10336191.html
Copyright © 2011-2022 走看看