我是靠谱客的博主 热心时光,这篇文章主要介绍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("%lldn",res);
}

 

最后

以上就是热心时光最近收集整理的关于51NOD 1163 最高的奖励的全部内容,更多相关51NOD内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(128)

评论列表共有 0 条评论

立即
投稿
返回
顶部