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 Data JPA 之 一对一,一对多,多对多 关系映射

    一.@OneToOne关系映射 JPA使用@OneToOne来标注一对一的关系. 实体 People :用户. 实体 Address:家庭住址. People 和 Address 是一对一的关系. 这 ...

  2. 杜教筛--51nod1239 欧拉函数之和

    求$\sum_{i=1}^{n}\varphi (i)$,$n\leqslant 1e10$. 这里先把杜教筛的一般套路贴一下: 要求$S(n)=\sum_{i=1}^{n}f(i)$,而现在有一数论 ...

  3. DELPHI IDFTP

    FTP是一个标准协议,它是在计算机和网络之间交换文件的最简单的方法. FTP也是应用TCP/IP协议的应用协议标准.FTP通常于将作者的文件上传至服务器,或从服务器上下传文件的一种普遍的使用方式作为用 ...

  4. <a href="ip地址" target=""_blank">a里面的target</a>

    HTML <a> 标签的 target 属性 定义和用法 <a> 标签的 target 属性规定在何处打开链接文档. 如果在一个 <a> 标签内包含一个 targe ...

  5. Spring Boot-Logback 配置(区分环境、分包、分级别打印)

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <!--生产环境 - ...

  6. SAS编程基础 - 逻辑库和数据集

    1. SAS逻辑库 1.1 创建SAS逻辑库: libname lb 'F:\Data_Model'; libname是关键字,lb是创建的逻辑库的名称,引号内的内容是目录路径,最后一个分号结束程序语 ...

  7. 关于warning

    IT男正吸着雪茄,吐着烟圈.他女朋友生气了发飙道:“你没看见包装盒上的警告(Warning)么?吸烟有害健康!” IT男淡定地回答道:“我是程序员.我们不关心警告,只关心错误.”

  8. cocos2d-x中绘制3D图形--3D ToolKit for cocos2dx实现原理

    首先:了解具体情况请看这里:https://github.com/wantnon2/3DToolKit-for-cocos2dx 在看代码之前,最好还是先把项目git下来执行一下demoproject ...

  9. android中单元測试中的断言assert的使用与扩展

    首先看一组对照,比方说我们要測试的结果是一个Linearlaout AssertJ Android: assertThat(layout).isVisible() .isVertical() .has ...

  10. linux恢复误删除文件-extundelete

     经过本人測试该工具支持ext3和ext4文件系统 当发现某个分区的数据被误删除后.要做的第一件事是立马卸载被误删除文件所在的分区,或者又一次以仅仅读方式挂载此分区. 这么做的原因事实上非常eas ...