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 ...
随机推荐
- discuz 注册用户用到的几个表
通过开启记录:mysql记录日志,筛出如下信息: INSERT INTO `userclub`.pre_ucenter_members SET secques='', username='pthlp1 ...
- PHP获取IP及地区信息(纯真IP数据库)
昨天在写程序的时候,发现在用户的时候记录IP和地区信息也许以后用得上,去网上找了找,发现实现的方式有好多好多,因为我用的ThinkPHP,后来又去TP官网找了找,最后采用了下面这种方法. <?p ...
- Gazebo Ros入门
教程代码 First step with gazebo and ros • setup a ROS workspace • create projects for your simulated rob ...
- sirius的学习笔记(2)
原文来自网络,侵权删 if both values of in a or expression are true ,Python will select the first one, and the ...
- 提取图像(tif)中水体的矢量数据(shp)研究
方法一:1、利用envi打开tif数据,原投影信息为beijing54.envi中没有这个投影。这里选择投影信息(WGS-84)选取水体roi——进行监督分类。这里可以对分类后进行处理(消除文字等干扰 ...
- Jsonp 跨域请求实例
关于jsonp的一个实例,其实自己也不是很了解,今天下午稍微研究了一下: 简单来说,jsonp就是为了两个不同网站之间数据传递而产生的,主要用于js脚本,因为浏览器本身是禁止跨域访问的: 本机实例: ...
- Mac OS X 10.10 Yosemite PHP 5.5.14 free type support fix
通过将php将至5.4来勉强支持freetype扩展,不推荐此方法 after upgrading to new Mac OS X Yosemite, i noticed that free type ...
- zoj 3620 Escape Time II dfs
题目链接: 题目 Escape Time II Time Limit: 20 Sec Memory Limit: 256 MB 问题描述 There is a fire in LTR ' s home ...
- mybatis--面向接口编程
如果使用hiberante作为dao层,常用的方式是:定义一个dao层接口包(com.dao.service)然后在定义一个dao层接口实现包(com.dao.service.impl),这样定义结构 ...
- Generating Huge reports in JasperReports
There are certain things to care while implementing the Jasper Reports for huge dataset to handle th ...