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. 使用Spring-Session共享使用Session

    前言: session共享策略有很多,常见的有粘性复制,高并发下效率查.tomcat-redis-session-manager无疑是一个挺好的方案,缺点要配置tomcat,有点复杂.最优的方案莫过于 ...

  2. MySQL查看表结构及查看建表语句

    查看表结构:desc 表名 mysql> use recommend; Database changed mysql> desc user; +--------------+------- ...

  3. 新装mvn建第一个项目报错org.apache.maven.plugins:maven-resources-plugin:2.6

    1.第一次创建mvn项目会报maven-resources-plugin-2.6.jar错,原因是mvn无法自动下载这个jar包,多次删除这个目录下的C:\Users\Administrator\.m ...

  4. 一起去打CS(codevs 5059)

    题目描述 Description 早就和lyk约好了去打cs,一直没找着时间,终于今天我家没人,他家也没人,总算可以出去了.但是偏偏天公不作美,某某人非要留那么多题要做.没办法只能尽快做完然后抓紧时间 ...

  5. Apache 使用localhost(127.0.0.1)可以访问,使用本机IP(局域网)不能访问

    本机ip是:192.168.1.25,输入后提示: Forbidden You don't have permission to access / on this server 对于此问题的解决办法, ...

  6. Ubuntu 16.04 GNOME无法使用拼音输入法问题

    说明:添加好之后重启!不然会出现输入错乱的问题. 参考: http://forum.ubuntu.org.cn/viewtopic.php?t=477765

  7. iOS 自己主动释放手动释放混编

    当项目为手动释放时,Build Settings中,Objective-c Automatic Reference Conting 为YES 时,想要手动管理一些文件,在CompileSources中 ...

  8. Mysql入门实战中

    前面一章主要解说了mysql的入门学习.包括数据库,表的管理,以及对数据的增删改,本章主要介绍mysql最重要的语句select的使用方法.将select的大部分使用方法进行分别解说. 全部代码下载( ...

  9. win7开启超级管理员账户(Administrator)

    win7开启超级管理员账户(Administrator) 不同于XP系统,Windows7系统据说出于安全的考虑,将超级管理员帐户"Administrator"在登陆界面给隐藏了, ...

  10. Lua中..和#运算符的用法

    Lua中..和#运算符的用法 样例 试试以下的样例就明确了在Lua编程语言提供的其它运算符: a = "Hello " b = "World" print(&q ...