Description

为了表示不能输给人类,农场的奶牛们决定成立一家航空公司.她们计划每天早晨,从密歇根湖湖岸的最北端飞向最南端,晚上从最南端飞往最北端.在旅途中,航空公司可以安排飞机停在某些机场.他们需要你帮助来决定每天携带哪些旅客.沿着湖岸,有N(1≤N≤10000)个由北至南编号为1到N的农场.每个农场都有一个机场.这天,有k(l≤七≤50000)群牛想要乘坐飞机旅行.每一群牛想要从一个农场飞往另一个农场.航班可以在某些农场停下带上部分或全体的牛.奶牛们登机后会一直停留直至达到目的地 提供给你飞机的容量C(1≤C≤100),同时提供给你想要旅行的奶牛的信息,请你计算出这一天的航班最多能够满足几只奶牛的愿望.

Input

第1行:3个用空格隔开的整数K,N和C.

第2到K+1行:每一行有3个用空格隔开的整数S,E,M.表示有M只奶牛想从农场S乘飞机到农场E.

Output

可以完成旅行的奶牛人数的最大值.

Sample Input

4 8 3

1 3 2

2 8 3

4 7 1

8 3 2

Sample Output

6


双倍经验题啊,参考[Usaco2009 Feb]庙会捷运Fair Shuttle,来回一趟,翻倍就好了啊

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10) print(x/10);
putchar(x%10+'0');
}
const int N=1e4,M=5e4;
int n,m,K,Ans;
struct S1{
int l,r,v;
void insert(int _l,int _r,int _v){l=_l,r=_r,v=_v;}
bool operator <(const S1 &x)const{return r!=x.r?r<x.r:l>x.l;}
}A[M+10];
struct Segment{
#define ls (p<<1)
#define rs (p<<1|1)
int tree[(N<<3)+10],Lazy[(N<<3)+10];
Segment(){
memset(tree,0,sizeof(tree));
memset(Lazy,0,sizeof(Lazy));
}
void build(int p,int l,int r){
tree[p]=K;
if (l==r) return;
int mid=(l+r)>>1;
build(ls,l,mid),build(rs,mid+1,r);
}
void Add_tag(int p,int v){tree[p]+=v,Lazy[p]+=v;}
void pushdown(int p){
if (!Lazy[p]) return;
Add_tag(ls,Lazy[p]);
Add_tag(rs,Lazy[p]);
Lazy[p]=0;
}
void Modify(int p,int l,int r,int x,int y,int v){
if (x<=l&&r<=y){
Add_tag(p,v);
return;
}
pushdown(p);
int mid=(l+r)>>1;
if (x<=mid) Modify(ls,l,mid,x,y,v);
if (y>mid) Modify(rs,mid+1,r,x,y,v);
tree[p]=min(tree[ls],tree[rs]);
}
int Query(int p,int l,int r,int x,int y){
if (x<=l&&r<=y) return tree[p];
pushdown(p);
int mid=(l+r)>>1,res=inf;
if (x<=mid) res=min(res,Query(ls,l,mid,x,y));
if (y>mid) res=min(res,Query(rs,mid+1,r,x,y));
return res;
}
}Tree;
int main(){
n=read(),m=read()<<1,K=read();
for (int i=1;i<=n;i++){
int x=read(),y=read(),z=read();
if (x<y) A[i].insert(x,y-1,z);
else A[i].insert(m-x,m-y-1,z);
}
sort(A+1,A+1+n);
Tree.build(1,1,m);
for (int i=1;i<=n;i++){
int tmp=min(A[i].v,Tree.Query(1,1,m,A[i].l,A[i].r));
Tree.Modify(1,1,m,A[i].l,A[i].r,-tmp),Ans+=tmp;
}
printf("%d\n",Ans);
return 0;
}

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

  1. bzoj1745[Usaco2005 oct]Flying Right 飞行航班*

    bzoj1745[Usaco2005 oct]Flying Right 飞行航班 题意: n个农场,有k群牛要从一个农场到另一个农场(每群由一只或几只奶牛组成)飞机白天从农场1到农场n,晚上从农场n到 ...

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

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

  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. 关于iphone 微信浏览器编码问题

    这个问题最终没有完美的解决,给出的一个解决方法是返回一个html文档.

  2. 共享一个NOI用过的vimrc [rc][vimrc]

    set nocp set nu set ru set noet set ai set cin set mouse =a set mp=g++\ %\ -o\ %<\ -g\ -Wall\ -Ws ...

  3. topshelf生成Windows服务

    一.  概述 Visual C# 工程中选取 Windows 服务(Windows Service)选项,可以创建Windows服务程序,这种开发方式对于开发来说不方便调试,今天介绍另外一种生成Win ...

  4. Codeforces 651C Watchmen【模拟】

    题意: 求欧几里得距离与曼哈顿距离相等的组数. 分析: 化简后得到xi=xj||yi=yj,即为求x相等 + y相等 - x与y均相等. 代码: #include<iostream> #i ...

  5. MongoDB小结07 - update【$addToSet & $each】

    用$addToSet更新可以避免重复,将它与$each组合起来,可以一次性添加多条(就算后添加的值已存在也没有关系) db.user.update({"name":"co ...

  6. 实战!利用MSF批量扫描校园网中含有MS17_010漏洞的主机并入侵

    利用ms17_010的永恒之蓝在前些日子火爆了一段时间,校园网中也声称封锁了相应端口.最近在搞MSF的深入学习,于是有了下文. ms17_010扫描工具 msf中的辅助模块含有一个强大的ms17_01 ...

  7. Windows如何安装MSMQ消息队列

    1 打开控制面板,找到下图所示的服务器核心,然点击确定 2 等待安装完成    

  8. 关于jQuery写插件及其演示

    关于写jQuery插件是非常有必要的.这是前端学习其中必须经过的一个过程 对于初次写插件先想清楚原理       (function($){  $.fn.yourName = function(opt ...

  9. 《软件project》——编码

       编码的目的是使用选定的程序设计语言,把模块的过程描写叙述翻译为用该语言书写的源程序. 源程序应该正确可靠.简明清晰,并且具有较高的效率.在编程的步骤中,要把软件具体设计的表达式翻译成为编程语言的 ...

  10. 两个月后才更新一篇。。。。LIB和DLL的差别

     共同拥有两种库: 一种是LIB包括了函数所在的DLL文件和文件里函数位置的信息(入口).代码由执行时载入在进程空间中的DLL提供,称为动态链接库dynamic link library. 一种是 ...