Description

正解:搜索+随机化。

先写个搜索,枚举所有没有要求的任务属于哪一种任务,然后再用爬山来更新最优解。

具体来说就是先把所有先做任务$A$的按照$a$时间从大到小排序,先做任务$B$的同。然后每次随机交换两个任务的位置,看这样会不会更优。

计算最优解写一个贪心就行了。

 #include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long using namespace std; struct data{ int t,a,b; }q[]; int st1[],st2[],vis[],n,ans,top1,top2; il int gi(){
RG int x=,q=; RG char ch=getchar();
while ((ch<'' || ch>'') && ch!='-') ch=getchar();
if (ch=='-') q=-,ch=getchar();
while (ch>='' && ch<='') x=x*+ch-,ch=getchar();
return q*x;
} il int cmp1(const int &x,const int &y){
if (q[x].b==q[y].b) return q[x].a<q[y].a;
return q[x].b>q[y].b;
} il int cmp2(const int &x,const int &y){
if (q[x].a==q[y].a) return q[x].b<q[y].b;
return q[x].a>q[y].a;
} il int calc(){
RG int ta=,tb=,res=;
for (RG int i=;i<=top2;++i) tb+=q[st2[i]].b;
for (RG int i=;i<=top1;++i){
ta+=q[st1[i]].a;
if (ta<tb) tb+=q[st1[i]].b;
else tb=ta+q[st1[i]].b;
}
res=tb,ta=tb=;
for (RG int i=;i<=top1;++i) ta+=q[st1[i]].a;
for (RG int i=;i<=top2;++i){
tb+=q[st2[i]].b;
if (tb<ta) ta+=q[st2[i]].a;
else ta=tb+q[st2[i]].a;
}
return max(res,ta);
} il void check(){
top1=top2=;
for (RG int i=;i<=n;++i)
if (vis[i]==) st1[++top1]=i; else st2[++top2]=i;
sort(st1+,st1+top1+,cmp1),sort(st2+,st2+top2+,cmp2);
RG int T=,a1,a2,b1,b2,tmp,res=calc();
while (T--){
if (top1) swap(st1[a1=rand()%top1+],st1[a2=rand()%top1+]);
if (top2) swap(st2[b1=rand()%top2+],st2[b2=rand()%top2+]);
tmp=calc(); if (res>=tmp){ res=tmp; continue; }
if (top1) swap(st1[a1],st1[a2]);
if (top2) swap(st2[b1],st2[b2]);
}
ans=min(ans,res); return;
} il void dfs(RG int x){
if (x>n){ check(); return; }
if (q[x].t!=) vis[x]=q[x].t,dfs(x+);
else vis[x]=,dfs(x+),vis[x]=,dfs(x+);
return;
} int main(){
#ifndef ONLINE_JUDGE
freopen("task.in","r",stdin);
freopen("task.out","w",stdout);
#endif
srand();
n=gi(),ans=<<;
for (RG int i=;i<=n;++i) q[i].t=gi(),q[i].a=gi(),q[i].b=gi();
dfs(),cout<<ans; return ;
}

bzoj2336 [HNOI2011]任务调度的更多相关文章

  1. [HNOI2011]任务调度

    题目描述 有 N 个任务和两台机器 A 与 B.每个任务都需要既在机器 A 上执行,又在机器 B 上执行, 第 i 个任务需要在机器 A 上执行时间 Ai,且需要在机器 B 上执行时间 Bi.最终的目 ...

  2. 2336: [HNOI2011]任务调度 - BZOJ

    一道随机算法的题目 随便用什么随机算法 首先我们可以想到枚举类型3的最终类型,然后再做 先贪心出一个较优的序列,首先我们知道肯定是在A机器上先做完类型1的事件再做类型2的事件,机器B也类似,因为这些没 ...

  3. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  4. .net 分布式架构之任务调度平台

    开源地址:http://git.oschina.net/chejiangyi/Dyd.BaseService.TaskManager .net 任务调度平台 用于.net dll,exe的任务的挂载, ...

  5. 免费开源的DotNet任务调度组件Quartz.NET(.NET组件介绍之五)

    很多的软件项目中都会使用到定时任务.定时轮询数据库同步,定时邮件通知等功能..NET Framework具有“内置”定时器功能,通过System.Timers.Timer类.在使用Timer类需要面对 ...

  6. Spring Quartz实现任务调度

    任务调度 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情 核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作 任务调度涉及多线程并发.线程池维 ...

  7. Quartz实现任务调度

    一.任务调度概述 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情,核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作,任务调度涉及多线程并发. ...

  8. 基于ASP.NET MVC(C#)和Quartz.Net组件实现的定时执行任务调度

    http://www.cnblogs.com/bobositlife/p/aspnet-mvc-csharp-quartz-net-timer-task-scheduler.html 在之前的文章&l ...

  9. Quartz任务调度基本使用

    转自:http://www.cnblogs.com/bingoidea/archive/2009/08/05/1539656.html 上一篇:定时器的实现.Java定时器Timer和Quartz介绍 ...

随机推荐

  1. 跨文件代码跳转插件:Ctags

    1.通过package control搜索Ctags 2.Enter安装,等待其安装完成 3.下载ctags可执行程序,链接:https://pan.baidu.com/s/1jIINAxo 密码:4 ...

  2. [转]weui-wxss WeUI for 小程序 为微信小程序量身设计

    本文转自:https://github.com/weui/weui-wxss/?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=tou ...

  3. Java中的断言 Assert

    今天正好遇到了,就记一下 一.作用: 用与编写单元测试 二.assert 关键字 assert 理论上和 if类似, 但是assert 仅仅用于测试, 不能用于业务 如果发现断言无效, 则可能时ide ...

  4. shell输入与输出功能

    一.shell输入功能 1. 2. 二.shell输出功能 1.字符界面前景颜色 2.字符界面背景颜色 3.其他输出命令 ①cat 输出文本,将文本的格式也输出 ②tee 既输出,也保存到文件里 ③m ...

  5. 讲解JavaScript两个圆括号、自调用和闭包函数

    一.JavaSript圆括号的使用 先来看一组通过函数声明来定义的函数: 先附代码: 运行结果如下: 这里我们可以看出: Ø  若没有加圆括号,则返回的是这个函数的内容 Ø  若加上圆括号,则返回的是 ...

  6. Android 录音getMaxAmplitude()

    这个方法是用来获取在前一次调用此方法之后录音中出现的最大振幅,文档解释如下: Returns the maximum absolute amplitude that was sampled since ...

  7. html 标签 显示模式

    1.html 标签模式分为三类:块级标签,行内标签(内联),行内块标签 a. 块级标签 典型代表:div.h1~h6.p.ul.ol.li.dl.dt.dd等. 特点:可以设置宽高,独占一行 b.行内 ...

  8. 获取当前时间CTime

    std::string getcurtime(){ USES_CONVERSION; CTime z_CurTime; CString z_TimeStr; z_CurTime = CTime::Ge ...

  9. 插入mysql语句报错:1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

    插入一个很简单的sql语句时候,mysql一直报错: [SQL] INSERT INTO ORDER ( id, activity_id, order_type, phone, order_amoun ...

  10. xlwings: Write Excel macro using python instead of VBA

    i want to write Excel macros to deal with the data, but i am not familiar with VBA language. so i de ...