Bzoj 3523 [Poi2014]Bricks
来源:互联网 发布:千峰软件测试 编辑:程序博客网 时间:2024/06/03 20:09
原题网址:http://www.lydsy.com/JudgeOnline/problem.php?id=3523
很显然的贪心,每次找不和前面元素重复的最多的,尾部颜色在数量相同时优先级更高。WA了好多发因为姿势丑,如果堆顶元素和前面元素一样只要先把堆顶拿出来就好了。。
type rec=record c,cnt:longint; end; const MAXN=1000050;var heap:array[0..MAXN] of rec; a,c,cp:array[0..MAXN] of longint; n,m,st,nd,i,cnt:longint; t:rec;procedure swp(var a,b:longint); var t:longint; begin t:=a;a:=b;b:=t; end;procedure swap(a,b:longint); begin swp(heap[a].c,heap[b].c); swp(heap[a].cnt,heap[b].cnt); end;operator >(a,b:rec)c:boolean; begin exit((a.cnt>b.cnt)or(a.cnt=b.cnt)and(a.c=nd));end; procedure heapup(x:longint); begin while ((x>1)and(heap[x]>heap[x>>1])) do begin swap(x,x>>1); x:=x>>1; end; end;procedure heapdown(x:longint); var e:longint; begin while ((x<<1<=cnt)and(heap[x<<1]>heap[x])or(x<<1+1<=cnt)and(heap[x<<1+1]>heap[x])) do begin e:=x<<1+ord((x<<1+1<=cnt)and(heap[x<<1+1].cnt>heap[x<<1].cnt)); swap(x,e); x:=e; end; end;procedure push(x:rec); begin inc(cnt); heap[cnt]:=x; heapup(cnt); end;procedure poop; begin heap[1]:=heap[cnt]; dec(cnt); heapdown(1); end;procedure no_solution; begin writeln(0); halt; end;begin read(n,st,nd);m:=0; for i:=1 to n do read(a[i]); cp:=a; for i:=1 to n do inc(m,a[i]); dec(a[st]);if (a[st]<0) then no_solution; dec(a[nd]);if (a[nd]<0) then no_solution; for i:=1 to n do if (a[i]>0) then begin t.c:=i; t.cnt:=a[i]; push(t); end; c[1]:=st;c[m]:=nd; for i:=2 to m-1 do if (heap[1].c<>c[i-1]) then begin c[i]:=heap[1].c; dec(heap[1].cnt); if (heap[1].cnt=0) then poop else heapdown(1); end else begin if (cnt=1) then no_solution; t:=heap[1];poop; c[i]:=heap[1].c; dec(heap[1].cnt); if (heap[1].cnt=0) then poop else heapdown(1); push(t); end; if (c[m]=c[m-1]) then no_solution; for i:=1 to m-1 do write(c[i],' '); writeln(c[m]);end.
0 0
- Bzoj 3523 [Poi2014]Bricks
- BZOJ3523: [Poi2014]Bricks
- [BZOJ 3523] Bricks 贪心+优先队列/堆
- [BZOJ3523][[Poi2014]Bricks][贪心+优先队列]
- BZOJ 3524: [Poi2014]Couriers
- bzoj 3524: [Poi2014]Couriers
- 【bzoj 3832】: [Poi2014]Rally
- bzoj 3832: [Poi2014]Rally
- BZOJ 3524: [Poi2014]Couriers
- BZOJ 3526 [Poi2014]Card
- BZOJ 3832 [Poi2014]Rally
- BZOJ 3524: [Poi2014]Couriers
- BZOJ 3524: [Poi2014]Couriers
- BZOJ 3522: [Poi2014]Hotel
- bzoj 3524 [Poi2014]Couriers
- BZOJ 3522 Poi2014 Hotel DFS
- Bzoj 3831 [Poi2014]Little Bird
- BZOJ 3831: [Poi2014]Little Bird
- domReady机制探究及DOMContentLoaded研究
- linux配置大页内存
- 简单Select语句
- AAC音频码流解析
- 【bzoj 1059】[ZJOI2007]矩阵游戏(匈牙利算法)
- Bzoj 3523 [Poi2014]Bricks
- 装饰者模式
- java 单链表
- 20个非常有用的Java程序片段
- HTML标签基础认识
- Java循环总结
- a bit of git
- ci Call to undefined function site_url()
- 母函数模板