zoukankan      html  css  js  c++  java
  • HDU2385Stock

     1 /*既然前一天的可以省下来给过后一天卖,那么就倒着卖,那么最后一天的只能在最后一天卖,如果可以卖完,还有可卖的名额,那么就从
     2 倒数第二天取,如果卖不完只能丢掉,而且必定是尽量留到价格最高的那一天卖*/
     3 /*HDU2385*/
     4 #include<stdio.h>
     5 #include<string.h>
     6 #include<queue>
     7 #include<algorithm>
     8 using namespace std;
     9 const int maxn=100000+10;
    10 struct N
    11 {
    12     int x,p,m;
    13    bool operator<(const N &a) const 
    14     {
    15         return p<a.p;
    16     }
    17 }node[maxn];
    18 int main()
    19 {
    20     int i,n;
    21     int t;
    22     scanf("%d",&t);
    23     priority_queue<N> q;
    24     N a;
    25     while(t--)
    26     {
    27         while(!q.empty()) q.pop();
    28         scanf("%d",&n);
    29         for(i=0;i<n;i++)
    30         {
    31             scanf("%d%d%d",&node[i].x,&node[i].p,&node[i].m);
    32         }
    33            int p=0,sum=0;
    34             for(i=n-1;i>=0;i--)
    35             {
    36                 q.push(node[i]);//
    37                 sum=node[i].x;
    38                 while(!q.empty()&&sum!=0)
    39                 {
    40                     a=q.top();//先找当天价格高的卖,里面存的是第i天以后的剩余名额
    41                     q.pop();
    42                     if(a.m>=sum)
    43                     {
    44                         a.m-=sum;
    45                         p+=a.p*sum;
    46                         sum=0;
    47                     }
    48                     else
    49                     {
    50                         sum-=a.m;
    51                         p+=a.p*a.m;
    52                         a.m=0;
    53                     }
    54                     if(a.m!=0)
    55                         q.push(a);//如果还有空闲的名额,那么继续留着向前找
    56                 }
    57                 if(q.empty())//卖不完只能丢掉,因为是倒着卖的
    58                     sum=0;
    59             }
    60             printf("%d
    ",p);
    61         }
    62     return 0;
    63 }
  • 相关阅读:
    LSMW TIPS
    Schedule agreement and Delfor
    Running VL10 in the background 13 Oct
    analyse idoc by creation date
    New Journey Prepare
    EDI error
    CBSN NEWS
    Listen and Write 18th Feb 2019
    Microsoft iSCSI Software Target 快照管理
    通过 Microsoft iSCSI Software Target 提供存储服务
  • 原文地址:https://www.cnblogs.com/okboy/p/3236612.html
Copyright © 2011-2022 走看看