• UVa1422 Processor


    关于这个题想强调一下这个时间点i的意义.

    在二分中有这句话

     while(cnt <= N && E[cnt].s < i) q.push(E[cnt++]); 

    我一开始不理解为什么起始时间严格小于 i 才能push进去, 网上好像也没有讲的.

    自己手玩了一下, 才明白实际上 i 可以理解成第 i 天的末尾.

    那么, 如果起始时间等于 i 的话相当于是在这一天的开头, 当然不能扔进去.

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <queue>
     6 using namespace std;
     7 const int MAXN = 1e5 + 20;
     8 
     9 int N;
    10 struct event
    11 {
    12     int s, t, w;
    13     bool operator <(const event &rhs) const{
    14         return t > rhs.t;
    15     }
    16 }E[MAXN];
    17 
    18 bool cmp1(const event &lhs, const event &rhs){
    19     return lhs.s < rhs.s;
    20 }
    21 int last = 0;
    22 
    23 inline bool check(int x)
    24 {
    25     priority_queue<event> q;
    26     int cnt = 1;
    27     for(int i = 1; i <= last; i++)
    28     {
    29         while(cnt <= N && E[cnt].s < i) q.push(E[cnt++]);
    30 
    31         int v = x;
    32         while(!q.empty() && v > 0)
    33         {
    34             event u = q.top(); q.pop();
    35             if(u.t < i) return false;
    36             if(u.w > v){
    37                 u.w -= v;
    38                 q.push(u);
    39                 break;
    40             } 
    41             else v -= u.w;
    42         }
    43         if(cnt == N + 1 && q.empty()) return true;
    44     }
    45     return false;
    46 }
    47 
    48 int main()
    49 {
    50     int T;
    51     cin>>T;
    52     while(T--)
    53     {
    54         last = 0;
    55         cin>>N;
    56         int l = 0, r = 0;
    57         for(int i = 1; i <= N; i++)
    58             scanf("%d%d%d", &E[i].s, &E[i].t, &E[i].w),
    59             r += E[i].w, last = max(last, E[i].t);
    60 
    61         sort(E + 1, E + N + 1, cmp1);
    62 
    63         #define mid (((l) + (r)) >> 1)
    64         while(l < r)
    65         {
    66             if(check(mid)) r = mid;
    67             else l = mid + 1;
    68         }
    69         printf("%d
    ", l);
    70     }
    71     return 0;
    72 }

     

  • 相关阅读:
    canvas 学习
    configure/autoconf/automake文件相关
    git add A 和 git add . 的区别详解
    Vim格Vim格式化代码功能——gg=G式化代码功能——gg=G
    详解git commit amend 用法
    git reset HEAD 与 git reset hard HEAD的区别 天地逍遥
    git的撤销操作:reset、checkout和revert
    参与linux社区
    git制作补丁
    git diff、git diff head、git diff cached三者详细区分
  • 原文地址:https://www.cnblogs.com/wsmrxc/p/9228194.html
Copyright © 2020-2023  润新知