zoukankan      html  css  js  c++  java
  • 51NOD 1163 最高的奖励

    来源:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163

    这个题 自己想了想 mmp 感觉一做贪心题只会用 sort 忽略了 优先队列

    这题搜了题解后 大概明白了  就是建立一个最小堆  把cost 压入最小堆 如果当前时间 》 Q.size() 说明可以直接加

    如果小于等于 就要把cost 压入后 取一个最小的出来 

    挺好的一个题

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn = 50000+10;
    
    struct node
    {
        int l,cost;
        bool operator <(const node & a)const{
            return l < a.l;
        }
    }s[maxn];
    
    int main ()
    {
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d%d",&s[i].l,&s[i].cost);
        sort(s,s+n);
        priority_queue<int,vector<int>,greater<int> > Q;
        ll res = 0;
        for(int i=0;i<n;i++)
        {
            if(s[i].l > Q.size()){
                res += s[i].cost;
                Q.push(s[i].cost);
            }
            else
            {
                res += s[i].cost;
                Q.push(s[i].cost);
                int t = Q.top();
                Q.pop();
                res -= t;
            }
        }
        printf("%lld
    ",res);
    }
  • 相关阅读:
    mysql外键添加error1215
    shell命令获取最新文件的名称
    centos7 apache提供文件下载
    centos7 时间设置
    微服务通信的类型
    angular-cli
    npm
    模块相关
    加油!冲冲冲
    软件评测
  • 原文地址:https://www.cnblogs.com/Draymonder/p/7352731.html
Copyright © 2011-2022 走看看