bzoj 5045: 打砖块 set
来源:互联网 发布:网络战略游戏 编辑:程序博客网 时间:2024/05/20 06:41
题意
小Q最近沉迷于一款新型《打砖块》游戏。在每局游戏中,呈现在屏幕上的是一堵无限大小的墙壁。墙壁上镶嵌着无数长度为2、宽度为1的砖块。墙壁被分成若干行,每行宽度都为1,相邻两个格子形成一个砖块。相邻两行的砖块是间隔摆放的。墙壁从下往上行编号递增,从左往右列编号递增。如下图所示:
在游戏的一开始,有n块砖块消失了。如果两块在同一行且相邻的砖块都消失了,那么玩家可以移除它们上方与它们都相邻的那一个砖块。请写一个程序帮助小Q计算最多可以让多少个位置没有砖块。
1<=n<=100000
分析
直接用set维护每一层的所有线段即可。
代码
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<set>#include<stack>using namespace std;typedef long long LL;const int N=100005;int n;pair<int,int> a[N];set<pair<int,int> > w;stack<pair<int,int> > sta,del;int read(){ int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}int main(){ n=read(); for (int i=1;i<=n;i++) a[i].first=read(),a[i].second=read(); sort(a+1,a+n+1); LL ans=0; for (int i=1;i<=n;i++) { if (a[i].first!=a[i-1].first&&i>1) { for (set<pair<int,int> >::iterator it=w.begin();it!=w.end();it++) { pair<int,int> u=*it;del.push(u); int len=(u.second-u.first+1)/2,tim=a[i].first-a[i-1].first; if (tim>=len) ans+=(LL)len*(len+1)/2; else ans+=(LL)len*(len+1)/2-(LL)(len-tim)*(len-tim+1)/2; u.first+=a[i].first-a[i-1].first;u.second-=a[i].first-a[i-1].first; if (u.first<u.second) sta.push(u); } while (!del.empty()) w.erase(del.top()),del.pop(); while (!sta.empty()) w.insert(sta.top()),sta.pop(); } pair<int,int> now=make_pair(a[i].second,a[i].second+1); if (!w.size()) { w.insert(now); continue; } set<pair<int,int> >::iterator it=w.lower_bound(now); if (it!=w.end()) { pair<int,int> u=*it; if (u.first<=now.first&&u.second>=now.second) continue; if (u.first==now.second+1) u.first=now.first,w.erase(it),now=u; } it=w.lower_bound(now); if (it!=w.begin()) { it--; pair<int,int> u=*it; if (u.first<=now.first&&u.second>=now.second) continue; if (u.second==now.first-1) u.second=now.second,w.erase(it),now=u; } w.insert(now); } for (set<pair<int,int> >::iterator it=w.begin();it!=w.end();it++) { int len=((*it).second-(*it).first+1)/2; ans+=(LL)len*(len+1)/2; } printf("%lld",ans); return 0;}
阅读全文
0 0
- bzoj 5045: 打砖块 set
- bzoj 5045: 打砖块
- bzoj 5045 打砖块 优先队列
- bzoj 1112 砖块|中位数|set
- 打砖块
- 打砖块
- 打砖块
- 打砖块游戏源码
- HNOI2004 打砖块
- Qt打砖块游戏
- android 打砖块游戏
- Linux C 打砖块
- 【HNOI2004】打砖块
- wiki 1257 打砖块
- unity3D__球打砖块
- 【codevs1257】打砖块 DP
- 【codevs1257】 打砖块
- 洛谷 P1174 打砖块
- 3171: [Tjoi2013]循环格
- Qt学习笔记-定时器的应用及精度设置
- Servlet使用适配器模式进行增删改查案例(IEmpService.java)
- Servlet使用适配器模式进行增删改查案例(DeptServiceImpl.java)
- Servlet使用适配器模式进行增删改查案例(EmpServiceImpl.java)
- bzoj 5045: 打砖块 set
- Servlet使用适配器模式进行增删改查案例(jdbc.properties)
- Servlet使用适配器模式进行增删改查案例(BaseServiceImplTest.java)
- CentOs6.8 hadoop集群搭建过程中的问题
- 上拉下拉加载数据的应用.....
- bzoj 5047: 空间传送装置 spfa
- 理解Angular中的$apply()以及$digest()
- Perl 入门实战:JVM 监控脚本(上)
- c语言实现单链表面试题(基础篇)