• bzoj4096 [Usaco2013 dec]Milk Scheduling


    Description

    Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes only one unit of time to milk. Being impatient animals, some cows will refuse to be milked if Farmer John waits too long to milk them. More specifically, cow i produces g_i gallons of milk (1 <= g_i <= 1000), but only if she is milked before a deadline at time d_i (1 <= d_i <= 10,000). Time starts at t=0, so at most x total cows can be milked prior to a deadline at time t=x. Please help Farmer John determine the maximum amount of milk that he can obtain if he milks the cows optimally. 
     
     

    Input

    * Line 1: The value of N. 
    * Lines 2..1+N: Line i+1 contains the integers g_i and d_i.

    Output

    * Line 1: The maximum number of gallons of milk Farmer John can obtain.

    Sample Input

    4
    10 3
    7 5
    8 1
    2 1
    INPUT DETAILS: There are 4 cows. The first produces 10 gallons of milk if milked by time 3, and so on.

    Sample Output

    25
    OUTPUT DETAILS: Farmer John milks cow 3 first, giving up on cow 4 since she cannot be milked by her deadline due to the conflict with cow 3. Farmer John then milks cows 1 and 2.
     
     
    倒序加入堆里,每次取出个价值最大的
     1 #include<cstdio>
     2 #include<iostream>
     3 #include<queue>
     4 #include<algorithm>
     5 #include<cstdlib>
     6 using namespace std;
     7 priority_queue<int> q;
     8 int n,tm,num,ans;
     9 struct dat{int c,w;}a[100100];
    10 bool operator <(const dat &a,const dat &b){return a.c>b.c;}
    11 int main()
    12 {
    13     q.empty();
    14     scanf("%d",&n);
    15     for (int i=1;i<=n;i++)scanf("%d%d",&a[i].w,&a[i].c);
    16     sort(a+1,a+n+1);
    17     tm=a[1].c;q.push(a[1].w);num=1;
    18     a[n+1].w=0;a[n+1].c=0;
    19     for (int i=2;i<=n+1;i++)
    20     {
    21         int go=min(tm-a[i].c,num);
    22         while (go!=0)ans+=q.top(),q.pop(),num--,go--;
    23         q.push(a[i].w);num++;tm=a[i].c;
    24     }
    25     printf("%d
    ",ans);
    26 }
    bzoj4096
    ——by zhber,转载请注明来源
  • 相关阅读:
    Silverlight 置于悬浮层之下 背景透明的方法
    做流媒体服务器需要什么(FMS)
    Silverlight WebClient 上传实现
    Silverlight WCF 初尝小结
    自动判断页面上的图片是否加载成功,不成功替换为默认图片
    HTTP PUSH技术原理,结合ASP.NET实现以及评述
    AJAX 请求队列实现
    关于COOKIES需要注意的一点
    Silverlight WCF 上传实现
    Silverlight 上传 大文件分块上传
  • 原文地址:https://www.cnblogs.com/zhber/p/4845185.html
Copyright © 2020-2023  润新知