bzoj1745[Usaco2005 oct]Flying Right 飞行航班

题意:

n个农场,有k群牛要从一个农场到另一个农场(每群由一只或几只奶牛组成)飞机白天从农场1到农场n,晚上从农场n到农场1,上面有c个座位,问最多可以满足多少只牛的要求。n≤10000,k≤50000,c≤100。

题解:

用类似贪心的方法做,现将每个农场出发的牛组织成链表。先求早上:当飞机到达每个农场时,先让到达的奶牛下机,接着如果飞机未满,则将其填满,之后枚举剩下的奶牛,如果它们的目的地比坐在飞机上面的奶牛目的地近,就将其替换为当前奶牛,这一过程可以用multiset维护。晚上所有过程都倒过来再做一次即可。

代码:

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#define inc(i,j,k) for(int i=j;i<=k;i++)
#define maxn 10010
using namespace std; inline int read(){
char ch=getchar(); int f=,x=;
while(ch<''||ch>''){if(ch=='-')f=-; ch=getchar();}
while(ch>=''&&ch<='')x=x*+ch-'',ch=getchar();
return f*x;
}
multiset<int,greater<int> >st1;
multiset<int>st2;
int n,m,k,now,ans; struct nd{int t,w,n;}nds[][maxn*]; int ess[],g[][maxn];
int main(){
n=read(); m=read(); k=read();
inc(i,,n){
int x=read(),y=read(),z=read();
if(x<y)nds[][++ess[]]=(nd){y,z,g[][x]},g[][x]=ess[];
else nds[][++ess[]]=(nd){y,z,g[][x]},g[][x]=ess[];
}
now=;
inc(i,,m){
if(st1.find(i)!=st1.end()){int x=st1.erase(i); ans+=x; now-=x;}
for(int j=g[][i];j;j=nds[][j].n){
while(now<k&&nds[][j].w)st1.insert(nds[][j].t),nds[][j].w--,now++;
if(now==k){
while(*st1.begin()>nds[][j].t&&nds[][j].w)
st1.erase(st1.begin()),st1.insert(nds[][j].t),nds[][j].w--;
}
}
}
now=;
for(int i=m;i>=;i--){
if(st2.find(i)!=st2.end()){int x=st2.erase(i); ans+=x; now-=x;}
for(int j=g[][i];j;j=nds[][j].n){
while(now<k&&nds[][j].w)st2.insert(nds[][j].t),nds[][j].w--,now++;
if(now==k){
while(*st2.begin()<nds[][j].t&&nds[][j].w)
st2.erase(st2.begin()),st2.insert(nds[][j].t),nds[][j].w--;
}
}
}
printf("%d",ans); return ;
}

20161115

bzoj1745[Usaco2005 oct]Flying Right 飞行航班*的更多相关文章

  1. bzoj1745: [Usaco2005 oct]Flying Right 飞行航班(贪心+map)

    之前做过一道基本一样的题目,抽象出来就是有个容量为c的载体,一些线段上某个点到另一个点要运输w个东西,求从头到尾最多能运多少东西. 这种模型可以用贪心做,用map,map[r]表示r的那个点,我们准备 ...

  2. [Usaco2005 oct]Flying Right 飞行航班

    Description 为了表示不能输给人类,农场的奶牛们决定成立一家航空公司.她们计划每天早晨,从密歇根湖湖岸的最北端飞向最南端,晚上从最南端飞往最北端.在旅途中,航空公司可以安排飞机停在某些机场. ...

  3. BZOJ 1684: [Usaco2005 Oct]Close Encounter

    题目 1684: [Usaco2005 Oct]Close Encounter Time Limit: 5 Sec  Memory Limit: 64 MB Description Lacking e ...

  4. 1684: [Usaco2005 Oct]Close Encounter

    1684: [Usaco2005 Oct]Close Encounter Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 387  Solved: 181[ ...

  5. bzoj1684 [Usaco2005 Oct]Close Encounter

    Description Lacking even a fifth grade education, the cows are having trouble with a fraction proble ...

  6. bzoj:1685 [Usaco2005 Oct]Allowance 津贴

    Description As a reward for record milk production, Farmer John has decided to start paying Bessie t ...

  7. 【BZOJ】1685: [Usaco2005 Oct]Allowance 津贴(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1685 由于每个小的都能整除大的,那么我们在取完大的以后(不超过c)后,再取一个最小的数来补充,可以证 ...

  8. 【BZOJ】1684: [Usaco2005 Oct]Close Encounter(暴力+c++)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1684 这货完全在考精度啊.. 比如奇葩 (llf)a/b*i (llf)(a/b*i)和(llf)( ...

  9. BZOJ 1685 [Usaco2005 Oct]Allowance 津贴:贪心【给硬币问题】

    题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1333 题意: 有n种不同币值的硬币,并保证大币值一定是小币值的倍数. 每种硬币的币值为 ...

随机推荐

  1. (九)maven-compiler-plugin 插件详解

    <plugin> <!-- 指定maven编译的jdk版本,如果不指定,maven3默认用jdk 1.5 maven2默认用jdk1.3 --> <groupId> ...

  2. MySQL数据表中有自增长主键时如何插入数据

    原文链接:https://blog.csdn.net/RuobaiMEN/article/details/79794199 MySQL数据库表中有自增主键ID,当用SQL插入语句中插入语句带有ID列值 ...

  3. mybatis的嵌套查询与嵌套结果查询的不同

    原文:https://blog.csdn.net/qq_39706071/article/details/85156840 实体类: 嵌套查询mapper方法:嵌套查询的弊端:即嵌套查询的N+1问题尽 ...

  4. 使用matplotlib进行可视化

    转自:https://blog.csdn.net/qq_30614345/article/details/99049790 https://blog.csdn.net/qq_30614345/arti ...

  5. 宝塔面板搭载yii2.0项目关于open_basedir报错解决办法

    昨天配置完宝塔的lamp后,然后把原本的yii项目放上去,发现出现三个报错,就是大概  require openssl之类的三个错误 然后去宝塔的界面里去配置了一个端口,然后再去阿里云上开放这个端口 ...

  6. router-view中绑定key='$route.fullPath'

    原文链接https://www.jianshu.com/p/cf2fb443620f 来源:简书 作者:myzony 不设置 router-view 的 key 属性 由于 Vue 会复用相同组件, ...

  7. 【Spring注解驱动开发】BeanPostProcessor在Spring底层是如何使用的?看完这篇我懂了!!

    写在前面 在<[String注解驱动开发]面试官再问你BeanPostProcessor的执行流程,就把这篇文章甩给他!>一文中,我们详细的介绍了BeanPostProcessor的执行流 ...

  8. 堆/题解 P3378 【【模板】堆】

    概念: 堆就是一颗二叉树,满足父亲节点总是比儿子节点大(小).因此,堆也分为大根堆和小根堆,大根堆就是父亲节点比儿子节点大,小根堆正好相反.注意加粗的地方,是每一个节点哦!!!!! 还是直接看例题吧, ...

  9. Centos 下 Jenkins2.6 + Git + Maven Shell一件部署与备份

    使用Jenkins2.6 集成Maven与Git插件做持续集成,同时编写Shell脚本备份与发布(需要稍微知道点Linux/毕竟基于Centos PS:本人Linux也是菜鸡) - 下载Jenkins ...

  10. CentOS 的数字命令级别

    1    user commands 2    system calls 3    library functions 4    special  files 5     file formats 6 ...