zoukankan      html  css  js  c++  java
  • [bzoj1029]建筑抢修

    先按照d从小到大排序,遍历所有建筑i,如果能修,显然要去修的
    考虑不能修,显然选择让之前所需时间最多的那个建筑不修(如果就是自己那就放弃),用堆来维护

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 struct ji{
     4     int t,d;
     5 }a[200005];
     6 priority_queue<int>q;
     7 int n,ans;
     8 long long t;
     9 bool cmp(ji x,ji y){
    10     return x.d<y.d;
    11 }
    12 int main(){
    13     scanf("%d",&n);
    14     for(int i=1;i<=n;i++)scanf("%d%d",&a[i].t,&a[i].d);
    15     sort(a+1,a+n+1,cmp);
    16     for(int i=1;i<=n;i++)
    17         if (t+a[i].t<=a[i].d){
    18             ans++;
    19             t+=a[i].t;
    20             q.push(a[i].t);
    21         }
    22         else{
    23             t-=max(q.top()-a[i].t,0);
    24             q.push(a[i].t);
    25             q.pop();
    26         }
    27     printf("%d",ans);
    28 }
    View Code
  • 相关阅读:
    Widget Factory
    233 Matrix
    青蛙的约会
    Longge's problem
    密码解锁
    SQFREE
    GCD
    [WC2011]最大XOR和路径
    [HNOI2011]XOR和路径
    [ZJOI2010]排列计数
  • 原文地址:https://www.cnblogs.com/PYWBKTDA/p/11629257.html
Copyright © 2011-2022 走看看