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

    Problem

    有N个任务,每个任务有一个最晚结束时间以及一个对应的奖励。在结束时间之前完成该任务,就可以获得对应的奖励。完成每一个任务所需的时间都是1个单位时间。有时候完成所有任务是不可能的,因为时间上可能会有冲突,这需要你来取舍。求能够获得的最高奖励。

    Solution

    时间排序,小根堆,每次加入,如果数量小于时间就加入,否则弹出一个加入。

    Code

    #include<stdio.h>
    #include<algorithm>
    #include<map>
    #include<queue>
    #include<vector>
    #include<string.h>
    #include<stack>
    
    #define mem(ss) memset(ss,0,sizeof(ss))
    #define fo(d, s, t) for(int d=s;d<=t;d++)
    #define fo0(d, s, t) for(int d=s;d>=t;d--)
    typedef long long ll;
    typedef long double ld;
    typedef double db;
    const ll mod = 998244353;
    #define io_opt ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
    using namespace std;
    
    ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
    
    db fab(db x) {
        return x > 0 ? x : -x;
    }
    
    int n;
    
    struct E {
        int t, w;
    
        bool operator<(const E &x) const {
            return this->w > x.w;
        }
    } e[50020];
    
    int cmp(E x, E y) {
        return x.t < y.t;
    }
    priority_queue<E>q;
    int cnt;
    ll ans;
    int main() {
        scanf("%d", &n);
        fo(i, 1, n) {
            scanf("%d%d", &e[i].t, &e[i].w);
        }
        sort(e + 1, e + 1 + n, cmp);
        fo(i,1,n){
            if(cnt<e[i].t){
                q.push(e[i]);
                cnt++;
            }
            else{
                if(e[i].w>q.top().w){
                    q.pop();
                    q.push(e[i]);
                }
            }
        }
        while(!q.empty()){
            ans+=q.top().w;
            q.pop();
        }
        printf("%lld
    ",ans);
        return 0;
    }
    
  • 相关阅读:
    ssh login nova vm
    Vxlan 原理
    nova的wsgi介绍【WIP】
    python entry points 例子
    libvirt python binding 变成了一个新项目
    libvirt python binding 变成了一个新项目了。
    ubuntu15.04下编译 libvirt
    qemu 调试(二)
    微信公众平台开发接口PHP SDK完整版
    php中单例模式的解析说明
  • 原文地址:https://www.cnblogs.com/sz-wcc/p/11663961.html
Copyright © 2011-2022 走看看