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\n", l);
70     }
71     return 0;
72 }

 

转载于:https://www.cnblogs.com/wsmrxc/p/9228194.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值