首页 技术 正文
技术 2022年11月12日
0 收藏 411 点赞 3,913 浏览 1222 个字

实际上和大多这类题一样(比如wikioi上的地鼠游戏),考察的都是堆的操作

这次改完之后就算把堆的模版定下来了

悲剧的是:大根堆打成了小根堆,导致一开始一直是10分……

按结束时间排序,(经过验证,结束时间相同的建筑不需要在根据t的大小来排序)

如果time+t[i]<=p[i] 那么直接将它加入堆中

如果上面的条件不满足,取出堆中的最大元素,如果time-a[1]+t[i]<=p[i] 那么将a[1]替换为t[i]

这样是因为这使得总完成任务数没变,但总时间却缩小了,不会比原来的决策差

代码:

 var  i,n,cnt,time:longint;
p,t,a:array[..] of longint;
procedure put(x:longint);
var i,k:longint;
begin
inc(cnt);
i:=cnt;k:=i>>;
while k>= do
begin
if a[k]<x then begin a[i]:=a[k];i:=k;k:=k>>;end
else k:=;
end;
a[i]:=x;
end;
procedure get(x:longint);
var i,k:longint;
begin
i:=;k:=i<<;
while k<=cnt do
begin
if (k<cnt) and (a[k+]>a[k]) then inc(k);
if a[k]>x then begin a[i]:=a[k];i:=k;k:=k<<;end
else k:=cnt+;
end;
a[i]:=x;
end;
procedure sort(h,l:longint);
var i,j,x,y,temp:longint;
begin
i:=h;j:=l;x:=p[(i+j)>>];y:=t[(i+j)>>];
repeat
while (p[i]<x) do inc(i);
while (p[j]>x) do dec(j);
if i<=j then
begin
temp:=p[i];p[i]:=p[j];p[j]:=temp;
temp:=t[i];t[i]:=t[j];t[j]:=temp;
inc(i);dec(j);
end;
until i>j ;
if i<l then sort(i,l);
if j>h then sort(h,j);
end;
procedure init;
begin
readln(n);
for i:= to n do readln(t[i],p[i]);
sort(,n);
end;
procedure main;
begin
time:=;
cnt:=;
for i:= to n do
begin
if time+t[i]<=p[i] then
begin
put(t[i]);inc(time,t[i]);continue;
end;
if (time-a[]+t[i]<=p[i]) and (t[i]<a[]) then
begin
inc(time,t[i]-a[]);get(t[i]);continue;
end;
end;
writeln(cnt);
end;
begin
init;
main;
end.
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898