zoukankan      html  css  js  c++  java
  • BZOJ2802 [Poi2012]Warehouse Store

    恩。。。贪心来着。。。

    我们先贪心当天能不能满足客户要求,如果能就尽量满足。

    好了现在不能满足怎么办?作为一个无良的商家,可以退掉以前的订单。。。(现实中真的可以?、、、)

    为了让当前剩余货物总量尽可能大,当然是退掉之前要求最高的订单喽,于是用堆维护一下就好了

    注意long long什么的就好了

     1 /**************************************************************
     2     Problem: 2802
     3     User: rausen
     4     Language: C++
     5     Result: Accepted
     6     Time:600 ms
     7     Memory:5108 kb
     8 ****************************************************************/
     9  
    10 #include <cstdio>
    11 #include <queue>
    12  
    13 using namespace std;
    14 typedef long long ll;
    15 const int N = 250005;
    16  
    17 struct data {
    18     int w, num;
    19     data() {}
    20     data(int _w, int _n) : w(_w), num(_n) {}
    21      
    22     inline bool operator < (const data &x) const {
    23         return num == x.num ? w < x.w : num < x.num;
    24     }
    25 };
    26  
    27 int n, ans;
    28 int a[N], b;
    29 bool u[N];
    30 ll now;
    31 priority_queue <data> h;
    32  
    33 inline int read() {
    34     int x = 0;
    35     char ch = getchar();
    36     while (ch < '0' || '9' < ch)
    37         ch = getchar();
    38     while ('0' <= ch && ch <= '9') {
    39         x = x * 10 + ch - '0';
    40         ch = getchar();
    41     }
    42     return x;
    43 }
    44  
    45 int main() {    
    46     int i;
    47     n = read();
    48     for (i = 1; i <= n; ++i)
    49         a[i] = read();
    50     for (i = 1; i <= n; ++i) {
    51         b = read();
    52         now += a[i];
    53         if (now > b)
    54             h.push(data(i, b)), now -= b, u[i] = 1, ++ans;
    55         else if (!h.empty() && h.top().num > b) {
    56             now += h.top().num - b, u[i] = 1, u[h.top().w] = 0;
    57             h.pop(), h.push(data(i, b));
    58         }
    59     }
    60     printf("%d
    ", ans);
    61     for (i = 1; i <= n; ++i)
    62         if (u[i]) printf("%d ", i);
    63     return 0;
    64 }
    View Code
    By Xs酱~ 转载请说明 博客地址:http://www.cnblogs.com/rausen
  • 相关阅读:
    Bzoj4627 [BeiJing2016]回转寿司
    Bzoj1901 Zju2112 Dynamic Rankings
    COGS728. [网络流24题] 最小路径覆盖问题
    Bzoj4568 [Scoi2016]幸运数字
    Bzoj2728 [HNOI2012]与非
    HDU4609 3-idiots
    Bzoj2194 快速傅立叶之二
    Bzoj2179 FFT快速傅立叶
    模拟52 题解
    模拟51 题解
  • 原文地址:https://www.cnblogs.com/rausen/p/4149895.html
Copyright © 2011-2022 走看看