zoukankan      html  css  js  c++  java
  • NYIST 1107 最高的奖励

    最高的奖励

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:3
     
    描述

    请问:挖掘机技术哪家强?AC了告诉你!

    给你N(N<=3*10^4)个任务,每个任务有一个截止完成时间t(1=<t<=10^9)和完成该任务的奖励v(1=<v<=10^9),每个任务要花一天完成,问最多能获得多少奖励?

    这是福利哦。。。

     
    输入
    多组 测试数据。
    第一行一个数N,表示任务总数。
    接下来N行,每行两个数t和v,如上所述。
    输出
    对于每组数据输出最高的奖励。
    样例输入
    7
    4 20
    2 60
    4 70
    3 40
    1 30
    4 50
    6 10
    样例输出
    230
    来源
    51nod
    上传者
    TC_赵坤垚

    解题:优先队列。。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <stack>
    13 #define LL long long
    14 #define INF 0x3f3f3f3f
    15 #define pii pair<int,int>
    16 using namespace std;
    17 const int maxn = 100000;
    18 pii d[maxn];
    19 int main(){
    20     int n,u,v;
    21     priority_queue< pii,vector< pii >,greater< pii > > q;
    22     while(~scanf("%d",&n)){
    23         LL ans = 0;
    24         while(!q.empty()) q.pop();
    25         for(int i = 0; i < n; ++i)
    26             scanf("%d %d",&d[i].first,&d[i].second);
    27         sort(d,d+n);
    28         for(int i = 0; i < n; ++i){
    29             if(q.size() < d[i].first){
    30                 ans += d[i].second;
    31                 q.push(make_pair(d[i].second,d[i].first));
    32             }else if(q.size() == d[i].first){
    33                 if(d[i].second > q.top().first){
    34                     ans += d[i].second - q.top().first;
    35                     q.pop();
    36                     q.push(make_pair(d[i].second,d[i].first));
    37                 }
    38             }
    39         }
    40         printf("%lld
    ",ans);
    41     }
    42     return 0;
    43 }
    View Code
  • 相关阅读:
    POJ3480 John 博弈论 anti-nim anti-SG
    POJ2068 Nim 博弈论 dp
    POJ 1740 A New Stone Game 又是博弈论配对找规律orz 博弈论 规律
    Python复习之下划线的含义
    django 模板语法和三种返回方式
    Python自动化之一对多
    Python自动化之django的ORM
    Python自动化之django的ORM操作——Python源码
    django orm字段和参数
    Python自动化之django视图
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4050105.html
Copyright © 2011-2022 走看看