• BZOJ1555 KD之死


    如果没有必选的限制条件,就是水题了、、、

    只要按照w + t排序就可以了,然后搞个堆来维护

    于是有了限制条件,还是水题。。。

    到了必选的时候强制选上,不加入堆中即可。

     1 /**************************************************************
     2     Problem: 1555
     3     User: rausen
     4     Language: C++
     5     Result: Accepted
     6     Time:2228 ms
     7     Memory:10948 kb
     8 ****************************************************************/
     9  
    10 #include <cstdio>
    11 #include <cctype>
    12 #include <algorithm>
    13 #include <queue>
    14  
    15 using namespace std;
    16 typedef long long ll;
    17 const int N  = 600005;
    18  
    19 struct data {
    20     int w, t, f;
    21 }a[N];
    22 bool operator < (const data &a, const data &b) {
    23     return (ll) a.w + a.t < (ll) b.w + b.t;
    24 }
    25  
    26 ll tot, V;
    27 int n, m, w, ans;
    28 priority_queue <int> q;
    29  
    30 inline ll read() {
    31     ll x = 0;
    32     char ch = getchar();
    33     while (!isdigit(ch))
    34         ch = getchar();
    35     while (isdigit(ch)) {
    36         x = x * 10 + ch - '0';
    37         ch = getchar();
    38     }
    39     return x;
    40 }
    41  
    42 inline void del_top() {
    43     tot -= q.top(), q.pop();
    44     --ans;
    45 }
    46  
    47 inline void add(int x) {
    48     tot += a[x].w, q.push(a[x].w);
    49     ++ans;
    50 }
    51  
    52 bool work() {
    53     int i;
    54     tot = 0;
    55     for (i = 1; i <= n; ++i)
    56         if (a[i].f == 1) {
    57             while (tot > a[i].t) {
    58                 if (q.empty()) return 0;
    59                 del_top();
    60             }
    61             tot += a[i].w, ++ans;
    62         }else {
    63             if (!q.empty() && tot > a[i].t)
    64                 if (q.top() < a[i].w || tot - q.top() > a[i].t)
    65                     continue;
    66             if (tot > a[i].t)
    67                 del_top();
    68             add(i);
    69         }
    70     return 1;
    71 }
    72  
    73 int main() {
    74     int i, X;
    75     n = read(), m = read(), V = read();
    76     for (i = 1; i <= n; ++i)
    77         a[i].w = read(), a[i].t = read();
    78     for (i = 1; i <= m; ++i) {
    79         X = read(), a[X].f = 1;
    80         tot += a[X].w;
    81     }
    82     sort(a + 1, a + n + 1);
    83     a[++n].f = 1, a[n].t = V;
    84     if (!work()) puts("Foolish SD!");
    85     else printf("%d
    ", ans - 1);
    86     return 0;
    87 }
    View Code

    (p.s. 怎么又想开fread二笔优化了呢、、、233)

    By Xs酱~ 转载请说明 博客地址:http://www.cnblogs.com/rausen
  • 相关阅读:
    前端线上项目汇总
    gulp构建工具学习汇总
    ES6知识点汇总
    页游技术点汇总中
    前后端方案汇总
    vim常用命令
    互联网哲学
    js调试技巧汇总中
    windows下Docker安装MySQL
    RabbitMQ几个常用面试题
  • 原文地址:https://www.cnblogs.com/rausen/p/4101539.html
Copyright © 2020-2023  润新知