NOI.AC-积木【堆】
生活随笔
收集整理的這篇文章主要介紹了
NOI.AC-积木【堆】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
正題
題目鏈接:http://noi.ac/contest/266/problem/794
題目大意
無限多個1?21*21?2的磚塊交替著
一個磚塊會掉落僅當下方兩個磚塊都掉落,現在抽出nnn個磚塊,求掉落多少個磚塊。
解題思路
開一個優先隊列,若兩個連在一起的就把上面那個加進去就好了,然后我們發現這樣會TLETLETLE。
我們可以將連著的存在一塊里就好了。
codecodecode
#include<cstdio> #include<cstring> #include<algorithm> #include<queue> #define ll long long using namespace std; const ll N=3e5+10; struct node{ll x,l,r; }v[N]; bool operator<(const node &x,const node &y) {return x.x==y.x?x.l>y.l:x.x>y.x;} ll n,ans,cnt; priority_queue<node> q; int main() {scanf("%lld",&n);for(ll i=1;i<=n;i++){ll x,y;scanf("%lld%lld",&x,&y);q.push((node){x,y,y+1});}while(!q.empty()){ll x=q.top().x;cnt=0;while(!q.empty()&&q.top().x==x)v[++cnt]=q.top(),q.pop();ll l=v[1].l,r=v[1].r;for(ll i=1;i<=cnt;i++){if(r+1>=v[i].l)r=max(v[i].r,r);else{if(l+1!=r)q.push((node){x+1,l+1,r-1});ans+=(r-l+1)/2;l=v[i].l;r=v[i].r;}}if(l+1!=r)q.push((node){x+1,l+1,r-1});ans+=(r-l+1)/2;}printf("%lld",ans); }總結
以上是生活随笔為你收集整理的NOI.AC-积木【堆】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NOI.AC-序列【堆】
- 下一篇: NOI.AC-保镖【贪心,对顶堆】