【JSOI2007】【Bzoj1029】建築搶修

來源:互聯網
上載者:User

標籤:ide   blocks   else   lin   std   http   bzoj1029   gif   return   

貪心。。。

按照T2來進行排序,用堆來進行維護。迴圈一遍,如果迴圈時間加上經過時間不超過截止時間,那就ANS++。否則,將它與堆頂判斷,如果小於堆頂就把堆頂踢出,把它加入。

 1 #include<cstdio> 2 #include<algorithm> 3 #include<queue> 4 using namespace std; 5 const int maxn=150010; 6 struct data{ 7     int la,e; 8 }a[maxn]; 9 int n;10 priority_queue <int> que;11 bool cmp(const data &x,const data &y){12     return x.e<y.e;13 }14 int main(){15     scanf("%d",&n);16     for (int i=1; i<=n; i++) scanf("%d%d",&a[i].la,&a[i].e);17     sort(a+1,a+n+1,cmp);18     long long now=0,ans=0;19     for (int i=1; i<=n; i++){20         int last=a[i].la;21         int en=a[i].e;22         if (now+last<=en){23             ans++;24             now+=last;25             que.push(last);26         }27         else {28             int tmp=que.top();29             if (tmp>last){30                 que.pop();31                 now=now-tmp+last;32                 que.push(last);33             }34         }35     }36     printf("%d\n",ans);37     return 0;38 } 
View Code

 

【JSOI2007】【Bzoj1029】建築搶修

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.