2336: [HNOI2011]任务调度 - BZOJ

一道随机算法的题目
随便用什么随机算法
首先我们可以想到枚举类型3的最终类型,然后再做
先贪心出一个较优的序列,首先我们知道肯定是在A机器上先做完类型1的事件再做类型2的事件,机器B也类似,因为这些没有等待时间,而他们做完了后续事情才能做
然后对类型1进行排序,按timeb为第一关键字降序(为了填补空隙,前面的越大排得就越紧密),按timea为第二关键字升序排序(尽量早点让类型1的B机器上的事先做),类型2的也类似
然后随机2000次左右(每次随机交换类型1的两个和类型2的两个)正确率就很高了
const
maxn=;
inf=;
type
node=record
kind,a,b,time:longint;
end;
var
a:array[..maxn]of node;
aa,bb,sa,sb:array[..maxn]of longint;
n,ans,ta,tb,numa,numb,suma,sumb:longint; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; function max(x,y:longint):longint;
begin
if x>y then exit(x);
exit(y);
end; procedure swap(var x,y:longint);
var
t:longint;
begin
t:=x;x:=y;y:=t;
end; procedure init;
var
i:longint;
begin
read(n);
for i:= to n do
with a[i] do
read(kind,a,b);
ans:=inf;
end; function geta:boolean;
var
k:longint;
begin
if numa>n then exit(false);
if numa>suma then k:=bb[numa-suma]
else k:=aa[numa];
if (a[k].kind=) or (a[k].time>) then
begin
ta:=max(ta,a[k].time)+a[k].a;
a[k].time:=ta;
inc(numa);
exit(true);
end;
exit(false);
end; function getb:boolean;
var
k:longint;
begin
if numb>n then exit(false);
if numb>sumb then k:=aa[numb-sumb]
else k:=bb[numb];
if (a[k].kind=) or (a[k].time>) then
begin
tb:=max(tb,a[k].time)+a[k].b;
a[k].time:=tb;
inc(numb);
exit(true);
end;
exit(false);
end; procedure get;
var
i,j,lastans:longint;
begin
suma:=;
sumb:=;
lastans:=inf;
for i:= to n do
if a[i].kind= then
begin
inc(suma);
sa[suma]:=i;
end
else
begin
inc(sumb);
sb[sumb]:=i;
end;
for i:=suma downto do
for j:= to i- do
if (a[sa[j+]].b>a[sa[j]].b) or ((a[sa[j+]].b=a[sa[j]].b) and (a[sa[j+]].a<a[sa[j]].a)) then swap(sa[j],sa[j+]);
for i:=sumb downto do
for j:= to i- do
if (a[sb[j+]].a>a[sb[j]].a) or ((a[sb[j+]].a=a[sb[j]].a) and (a[sb[j+]].b<a[sb[j]].b)) then swap(sb[j],sb[j+]);
for j:= to do
begin
aa:=sa;
bb:=sb;
if suma<> then
swap(aa[random()mod suma+],aa[random()mod suma+]);
if sumb<> then
swap(bb[random()mod sumb+],bb[random()mod sumb+]);
for i:= to n do
a[i].time:=;
ta:=;
tb:=;
numa:=;
numb:=;
while (numa<=n) or (numb<=n) do
begin
if ta<tb then
begin
if geta=false then getb;
end
else
if getb=false then geta;
end;
if lastans>=max(ta,tb) then
begin
lastans:=max(ta,tb);
ans:=min(lastans,ans);
sa:=aa;
sb:=bb;
end;
end;
end; procedure try(x:longint);
begin
if x=n+ then get
else
if a[x].kind= then
begin
a[x].kind:=;
try(x+);
a[x].kind:=;
try(x+);
a[x].kind:=;
end
else try(x+);
end; begin
randomize;
init;
try();
write(ans);
end.
2336: [HNOI2011]任务调度 - BZOJ的更多相关文章
- [HNOI2011]任务调度
题目描述 有 N 个任务和两台机器 A 与 B.每个任务都需要既在机器 A 上执行,又在机器 B 上执行, 第 i 个任务需要在机器 A 上执行时间 Ai,且需要在机器 B 上执行时间 Bi.最终的目 ...
- bzoj2336 [HNOI2011]任务调度
Description 正解:搜索+随机化. 先写个搜索,枚举所有没有要求的任务属于哪一种任务,然后再用爬山来更新最优解. 具体来说就是先把所有先做任务$A$的按照$a$时间从大到小排序,先做任务$B ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 2326: [HNOI2011]数学作业( 矩阵快速幂 )
BZOJ先剧透了是矩阵乘法...这道题显然可以f(x) = f(x-1)*10t+x ,其中t表示x有多少位. 这个递推式可以变成这样的矩阵...(不会用公式编辑器...), 我们把位数相同的一起处理 ...
- ●BZOJ 2329 [HNOI2011]括号修复.cpp
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2329 题解: Splay 类似 BZOJ 2329 [HNOI2011]括号修复 只是多了一 ...
- 【概率DP/高斯消元】BZOJ 2337:[HNOI2011]XOR和路径
2337: [HNOI2011]XOR和路径 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 682 Solved: 384[Submit][Stat ...
- [BZOJ 2326] [HNOI2011] 数学作业 【矩阵乘法】
题目链接:BZOJ - 2326 题目分析 数据范围达到了 10^18 ,显然需要矩阵乘法了! 可以发现,向数字尾部添加一个数字 x 的过程就是 Num = Num * 10^k + x .其中 k ...
- BZOJ 2329: [HNOI2011]括号修复( splay )
把括号序列后一定是))))((((这种形式的..所以维护一个最大前缀和l, 最大后缀和r就可以了..答案就是(l+1)/2+(r+1)/2...用splay维护,O(NlogN). 其实还是挺好写的, ...
- BZOJ 2337: [HNOI2011]XOR和路径( 高斯消元 )
一位一位考虑异或结果, f(x)表示x->n异或值为1的概率, 列出式子然后高斯消元就行了 --------------------------------------------------- ...
随机推荐
- 转 Android中this、super的区别
在Java中,this通常指当前对象,super则指父类的.当你想要引用当前对象的某种东西,比如当前对象的某个方法,或当前对象的某个成员,你便可以利用this来实现这个目 的,当然,this的另一个用 ...
- BootStrap glyphicons字体图标
本章将讲解Bootstrap glyphicons字体图标,并通过一些实例了解它的使用,字体图标是在 Web 项目中使用的图标字体.字体图标在下载的Bootstrap的fonts文件夹中 本章将讲 ...
- TSQL基础(二)
over() 开窗函数 排名函数必须和over()一起使用,所以先了解over(). OVER 子句定义查询结果集内的窗口或用户指定的行集. 然后,开窗函数将计算窗口中每一行的值. 您可以将 OVER ...
- 实现Foreach遍历
实现Foreach遍历的集合类,需要实现IEnumerable接口,泛型集合则需要实现IEnumerable<T>接口 using System; using System.Collect ...
- firebug调试js时提示调试器未激活处理办法
firebug是web开发中最常用的分析调试软件,不过我今天使用在调试百度在线编辑器UEditor时一直提示调试器未激活. 从使用经验来看不应该啊,我都下了断点了为什么会提示调试器未激活呢!多次载入网 ...
- Memcached学习(三)
通过Java客户端实现与Memcached的交互,Java客户端的实现了使用了开源的Memcached-Java-Client,开源地址在GitHub上. 如下是通过该开源库实现的Memcached交 ...
- Struts升级到2.3.15.1抵抗漏洞
后知后觉,今天才开始修复Struts2的漏洞 详细情形可以参考: http://struts.apache.org/release/2.3.x/docs/security-bulletins.html ...
- spring自定义注解
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- CSS笔记---文字两边对齐
<style> .box{ width: 1000px; height: 500px; background-color: #aa0000; margin:0 auto; } .teste ...
- CSS Sprites优点
在分析各个网站的CSS时,我们经常可以看到一些网站有很多的元素共享了一张背景图片,而这张背景图片包含了所有这些元素需要的背景,这种技术就叫做CSS Sprites. 例如淘宝的css sprites ...