Codevs 2995 楼房
来源:互联网 发布:windows xp安装不了 编辑:程序博客网 时间:2024/06/08 03:08
2995 楼房
时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold
1 #include<cstdio> 2 #include<queue> 3 #include<algorithm> 4 using namespace std; 5 #define N 100100 6 struct ss{ 7 int h,l,r; 8 bool operator < (const ss &a) const{ 9 if(l==a.l) return h>a.h;10 return l<a.l;11 }12 }e[N<<1];13 struct node{14 int h,r;15 node(ss x){ h=x.h;r=x.r; }16 bool operator < (const node &a) const{17 return h<a.h;18 }19 };20 int n,cnt;21 pair<int,int>ans[N<<2];22 priority_queue<node>que;23 ss bfs(ss now,int x){24 while(!que.empty()){25 node nown=que.top();que.pop();26 if(nown.r>now.r){27 if(nown.h!=now.h){28 ans[++cnt]=make_pair(now.r,now.h);29 ans[++cnt]=make_pair(now.r,nown.h);30 }31 now.r=nown.r;now.h=nown.h;32 }33 if(now.r>=x) return now;34 }35 ans[++cnt]=make_pair(now.r,now.h);36 ans[++cnt]=make_pair(now.r,0);37 now.h=0;now.r=0x7fffffff;38 return now;39 }40 void solve(){41 ans[++cnt]=make_pair(e[1].l,0);42 ans[++cnt]=make_pair(e[1].l,e[1].h);43 ss now=e[1];44 for(int i=2;i<=n;i++){45 if(now.h>=e[i].h&&now.r>=e[i].l)que.push(e[i]);46 if(now.h<e[i].h&&now.r>=e[i].l){47 que.push(now);48 ans[++cnt]=make_pair(e[i].l,now.h);49 now=e[i];50 ans[++cnt]=make_pair(e[i].l,now.h);51 }52 if(now.r<e[i].l){53 now=bfs(now,e[i].l);54 if(now.h>=e[i].h&&now.r>=e[i].l)55 que.push(e[i]);56 if(now.h<e[i].h&&now.r>=e[i].l){57 que.push(now);58 ans[++cnt]=make_pair(e[i].l,now.h);59 now=e[i];60 ans[++cnt]=make_pair(e[i].l,now.h);61 }62 }63 }64 bfs(now,0x7fffffff);65 }66 int main(){67 scanf("%d",&n);68 for(int i=1;i<=n;i++)69 scanf("%d%d%d",&e[i].h,&e[i].l,&e[i].r);70 sort(e+1,e+1+n);71 solve();72 printf("%d\n",cnt);73 for(int i=1;i<=cnt;i++)74 printf("%d %d\n",ans[i].first,ans[i].second);75 return 0;76 }
0 0
- Codevs 2995 楼房
- Codevs 2995 楼房
- 楼房
- 楼房开盘
- 楼房重建
- Codevs
- 狗舍、村屋、楼房
- bzoj 2957 楼房重建
- bzoj 2957: 楼房重建
- bzoj-2957 楼房重建
- 【THUSC 2013】楼房重建
- BZOJ 2957 楼房重建
- 【BZOJ2957】楼房重建
- bzoj 2957: 楼房重建
- bzoj2957: 楼房重建
- bzoj2957 楼房重建
- BZOJ2957 楼房重建
- 2957: 楼房重建
- 开发环境:(2)配置Maven远端仓库
- 洛谷 P1160 队列安排
- 合并排序(归并排序)的C语言实现
- 洛谷 P1131 选择客栈
- Codevs 1501 二叉树的最大宽度和高度
- Codevs 2995 楼房
- 微信授权获取用户列表
- next数组介绍
- POJ 2421 Constructing Roads
- 在WPF中强制捕获鼠标,鼠标移出控件后依然何以获取鼠标事件
- POJ 1789 Truck History
- POJ 1125 Stockbroker Grapevine
- POJ 3037 Skiing
- POJ 3461 Oulipo