bzoj1293
简易贪心+heap
注意要用链表
type link=^node;
node=record
loc:longint;
next:link;
end;
point=record
loc,num:longint;
end;
var w,b:array[..] of link;
heap:array[..] of point;
n,k,s,x,i,j,y,t,ans:longint;
p,q:link; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; procedure swap(var a,b:point);
var c:point;
begin
c:=a;
a:=b;
b:=c;
end; procedure up(i:longint);
var j:longint;
begin
j:=i shr ;
while j> do
begin
if heap[i].loc<heap[j].loc then
begin
swap(heap[i],heap[j]);
i:=j;
j:=i shr ;
end
else break;
end;
end; procedure sift(i:longint);
var j:longint;
begin
j:=i shl ;
while j<=k do
begin
if (j+<=k) and (heap[j].loc>heap[j+].loc) then inc(j);
if heap[i].loc>heap[j].loc then
begin
swap(heap[i],heap[j]);
i:=j;
j:=i shl ;
end
else break;
end;
end; begin
readln(n,k);
for i:= to k do
begin
read(s);
w[i]:=nil;
for j:= to s do
begin
read(x);
new(p);
p^.next:=nil;
p^.loc:=x;
if w[i]=nil then
begin
w[i]:=p;
q:=p;
end
else begin
q^.next:=p;
q:=p;
end;
end;
b[i]:=w[i];
readln;
end;
y:=;
for i:= to k do
begin
t:=t+;
heap[t].loc:=b[i]^.loc;
heap[t].num:=i;
up(t);
if heap[t].loc>y then y:=heap[t].loc;
b[i]:=b[i]^.next;
end;
ans:=y-heap[].loc;
while true do
begin
x:=heap[].num;
if b[x]=nil then break
else begin
heap[].loc:=b[x]^.loc;
if y<b[x]^.loc then y:=b[x]^.loc;
b[x]:=b[x]^.next;
sift();
ans:=min(ans,y-heap[].loc);
end;
end;
writeln(ans);
end.
bzoj1293的更多相关文章
- BZOJ1293 [SCOI2009]生日礼物 离散化
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1293 题意概括 彩珠有N个,分为K种.每一个彩珠有一个对应的坐标.坐标上可以没有彩珠,多个彩珠也可 ...
- 【BZOJ1293】[SCOI2009]生日礼物(单调队列)
[BZOJ1293][SCOI2009]生日礼物(单调队列) 题面 BZOJ 洛谷 题解 离散之后随便拿单调队列维护一下就好了. #include<iostream> #include&l ...
- bzoj1293: [SCOI2009]生日礼物
单调队列 用一个堆维护目前每个颜色在里面的点,每回取出队首点,并更新答案.一旦哪个颜色的点都被用完,跳出循环. #include<cstdio> #include<algorithm ...
- bzoj1293[SCOI2009]生日礼物 尺取法
1293: [SCOI2009]生日礼物 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2838 Solved: 1547[Submit][Stat ...
- bzoj1293 生日礼物
Description 小西有一条很长的彩带,彩带上挂着各式各样的彩珠.已知彩珠有N个,分为K种.简单的说,可以将彩带考虑为x轴,每一个彩珠有一个对应的坐标(即位置).某些坐标上可以没有彩珠,但多个彩 ...
- BZOJ1293:[SCOI2009]生日礼物——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1293 https://www.luogu.org/problemnew/show/P2564#sub ...
- BZOJ1293 [SCOI2009]生日礼物 【队列】
题目 小西有一条很长的彩带,彩带上挂着各式各样的彩珠.已知彩珠有N个,分为K种.简单的说,可以将彩带考虑为x轴,每一个彩珠有一个对应的坐标(即位置).某些坐标上可以没有彩珠,但多个彩珠也可以出现在同一 ...
- 【堆】bzoj1293 [SCOI2009]生日礼物
考虑poj3320尺取法的做法,与此题基本一样,但是此题的 位置 的范围到2^31 尺取法不可. 将每种珠子所在的位置排序. 每种珠子要维护一个指针,指到已经用到这个种类的哪个珠子. 所以尺取法用堆优 ...
- BZOJ1293:[SCOI2009]生日礼物
浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?i ...
随机推荐
- [译]servlet3.0与non-blocking服务端推送技术
Non-blocking(NIO)Server Push and Servlet 3 在我的前一篇文章写道如何期待成熟的使用node.js.假定有一个框架,基于该框架,开发者只需要定义协议及相关的ha ...
- Using jQuery to add a dynamic “Back To Top” floating button with smooth scroll
Ever read a really long blog post or article and then had to scroll all the way up to the top of the ...
- 通过 SuperObject 生成 json string
(* { "name": "Henri Gourvest", /* this is a comment */ "vip": true, &q ...
- IEEE 754 浮点数的四种舍入方式
四种舍入方向: 向最接近的可表示的值:当有两个最接近的可表示的值时首选"偶数"值:向负无穷大(向下):向正无穷大(向上)以及向0(截断). 说明:默认模式是最近舍入(Round t ...
- Ubuntu虚拟机与Window、Arm的通信
Ubuntu虚拟机与Window的通信安装有Ubuntu14.04的虚拟机VMware,将虚拟机的网络适配器配置成NAT类型(默认使用VMnet8进行通信),此时将Ubuntu的IP地址设置成与VMn ...
- Hive[5] HiveQL 数据操作
5.1 向管理表中装载数据 Hive 没有行级别的数据插入更新和删除操作,那么往表中装载数据的唯一途径就是使用一种“大量”的数据装载操作,或者通过其他方式仅仅将文件写入到正确的目录下: LOA ...
- Flasback数据库(闪回数据库)
数据库闪回原理: 一旦启用了闪回数据库,修改的块映像会不时从数据库缓冲区复制到闪回缓冲区.通过新的后台恢复写入器(Recovery Writer, RVWR)将此闪回缓冲区内容刷新到磁盘和闪回日志接着 ...
- 一、mysql使用入门
mysql -h localhost -u root -p123456 登录mysql服务器 show databases 列出所拥有的数据库 use www 选择一个www的数据库 show tab ...
- Unity3d读取.csv文件
原文地址:http://blog.csdn.net/dingkun520wy/article/details/26594991 (一)文件路径 需要把csv文件放在StreamingAssets这个文 ...
- dive into python 读笔(3)
chapter 6 异常和文件处理: # 使用 try...except 来捕捉异常 # 使用 try...finally 来保护额外的资源 # 读取文件 # 在一个 for循环中一次赋多个值 # 使 ...