bzoj 5045: 打砖块
来源:互联网 发布:软件版权说明 编辑:程序博客网 时间:2024/06/09 19:47
题解:
一道不太难的题,比赛时就A了。
就将每一层的砖插入堆里面,合并下,再往上加,就可以了。
最多就2n。
code:
#include<queue>#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#define LL long longusing namespace std;struct node{ int y,x1,x2; bool operator < (node a) const{if(a.x1==x1) return a.x2>x2;return a.x1<x1;}}a[100010],b[200010];int tot;LL ans=0;priority_queue<node> q;int n,pos;bool cmp(node a,node b){ if(a.y==b.y) return a.x1<b.x1; return a.y<b.y;}void solve(int y,int c){ if(c==0&&q.empty()) return; tot=0; while(c<=n&&a[c].y==y) { node tmp;tmp.x1=a[c].x1;tmp.x2=a[c].x2; q.push(tmp); pos++;c++; } node now;bool first=true; while(!q.empty()) { node t=q.top();q.pop(); if(first) now=t,first=false; else { if(now.x2+1>=t.x1) now.x2=max(now.x2,t.x2); else b[++tot]=now,now=t; } } b[++tot]=now; for(int i=1;i<=tot;i++) { int l=b[i].x1,r=b[i].x2; ans+=(LL)(r-l+1)/2; if(l+1<r) { node tmp; tmp.x1=l+1;tmp.x2=r-1; q.push(tmp); } } if(pos<=n&&a[pos].y==y+1) solve(y+1,pos); else solve(y+1,0);}int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d %d",&a[i].y,&a[i].x1),a[i].x2=a[i].x1+1; sort(a+1,a+n+1,cmp); while(!q.empty()) q.pop(); pos=1; while(pos<=n) solve(a[pos].y,pos); printf("%lld",ans);}
阅读全文
2 0
- bzoj 5045: 打砖块
- bzoj 5045: 打砖块 set
- bzoj 5045 打砖块 优先队列
- 打砖块
- 打砖块
- 打砖块
- 打砖块游戏源码
- HNOI2004 打砖块
- Qt打砖块游戏
- android 打砖块游戏
- Linux C 打砖块
- 【HNOI2004】打砖块
- wiki 1257 打砖块
- unity3D__球打砖块
- 【codevs1257】打砖块 DP
- 【codevs1257】 打砖块
- 洛谷 P1174 打砖块
- 洛谷 P1174 打砖块
- 一文搞懂各种 Docker 网络
- HDU——1020 Encoding
- Ubuntu硬盘只读文件系统
- 使用两个栈实现一个队列
- 短信验证码功能开发
- bzoj 5045: 打砖块
- 大数据(二十一)Hive【Hive【DDL语句】】
- LuaFramework案例_01
- android调试篇之eclipse 一:wait for debug
- Improving Deep Neural Networks Tensorflow 参考答案
- LeekCode:03:Longest Substring Without Repeating Characters
- 数据库视频总结(一)
- 高并发的解决方案
- Spark Streaming总结