Bzoj1572 [Usaco2009 Open]工作安排Job
2016-10-27 20:15
435 查看
原题网址:http://www.lydsy.com/JudgeOnline/problem.php?id=1572
反过来做,每个任务都有一个开始时间,到了开始时间就压进堆里,每秒弹出一个价值最高的。
反过来做,每个任务都有一个开始时间,到了开始时间就压进堆里,每秒弹出一个价值最高的。
var d,v,heap:array[0..100050] of longint; n,i,time,cnt,p:longint; ans:int64; procedure swap(var a,b:longint); var t:longint; begin t:=a;a:=b;b:=t;end; procedure sort(l,r:longint); var i,j,e:longint; begin i:=l;j:=r;e:=d[(l+r)>>1]; repeat while d[i]>e do inc(i); while e>d[j] do dec(j); if not (i>j) then begin swap(d[i],d[j]); swap(v[i],v[j]); inc(i);dec(j); end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; procedure heapup(x:longint); begin while ((x>1)and(heap[x]>heap[x>>1])) do begin swap(heap[x],heap[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 if ((x<<1+1<=cnt)and(heap[x<<1+1]>heap[x<<1])) then e:=x<<1+1 else e:=x<<1; swap(heap[x],heap[e]); x:=e; end; end; procedure push(x:longint); begin inc(cnt); heap[cnt]:=x; heapup(cnt); end; procedure poop; begin heap[1]:=heap[cnt]; dec(cnt); heapdown(1); end; begin read(n); for i:=1 to n do read(d[i],v[i]); sort(1,n); time:=1000000000; cnt:=0;p:=0;ans:=0; repeat while ((p+1<=n)and(d[p+1]=time)) do begin inc(p); push(v[p]); end; if (cnt>0) then begin inc(ans,heap[1]); poop; end; if (cnt=0)and(p<n) then time:=d[p+1] else dec(time); until (p=n)and(cnt=0)or(time=0); writeln(ans); end.
相关文章推荐
- bzoj1572 [Usaco2009 Open]工作安排Job(贪心)
- [bzoj1572]: [Usaco2009 Open]工作安排Job
- bzoj 1572: [Usaco2009 Open]工作安排Job【贪心+堆】
- 【BZOJ1572】【usaco 2009 open】工作安排job
- 【bzoj1572】[Usaco2009 Open]工作安排Job 贪心+堆
- bzoj1572 [Usaco2009 Open]工作安排Job
- bzoj1572 [Usaco2009 Open]工作安排Job【贪心 堆】
- bzoj1572[Usaco2009 Open]工作安排Job 堆
- BZOJ1572 [Usaco2009 Open]工作安排Job
- BZOJ 1572[Usaco2009 Open]工作安排Job
- BZOJ1572 [Usaco2009 Open]工作安排Job
- bzoj1572 [Usaco2009 Open]工作安排Job
- BZOJ1572: [Usaco2009 Open]工作安排Job 贪心
- BZOJ 1572: [Usaco2009 Open]工作安排Job( 贪心 )
- bzoj1572 [Usaco2009 Open]工作安排Job
- [BZOJ1572] [Usaco2009 Open]工作安排Job(贪心 + 堆)
- [bzoj1572][Usaco2009 Open]工作安排Job_贪心_堆
- 【BZOJ 1572】 1572: [Usaco2009 Open]工作安排Job(贪心+优先队列)
- BZOJ1572: [Usaco2009 Open]工作安排Job
- [BZOJ1572][Usaco2009 Open]工作安排Job(贪心+堆)