[Usaco2005 oct]Flying Right 飞行航班
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 飞行航班的更多相关文章
- bzoj1745[Usaco2005 oct]Flying Right 飞行航班*
bzoj1745[Usaco2005 oct]Flying Right 飞行航班 题意: n个农场,有k群牛要从一个农场到另一个农场(每群由一只或几只奶牛组成)飞机白天从农场1到农场n,晚上从农场n到 ...
- bzoj1745: [Usaco2005 oct]Flying Right 飞行航班(贪心+map)
之前做过一道基本一样的题目,抽象出来就是有个容量为c的载体,一些线段上某个点到另一个点要运输w个东西,求从头到尾最多能运多少东西. 这种模型可以用贪心做,用map,map[r]表示r的那个点,我们准备 ...
- BZOJ 1684: [Usaco2005 Oct]Close Encounter
题目 1684: [Usaco2005 Oct]Close Encounter Time Limit: 5 Sec Memory Limit: 64 MB Description Lacking e ...
- 1684: [Usaco2005 Oct]Close Encounter
1684: [Usaco2005 Oct]Close Encounter Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 387 Solved: 181[ ...
- bzoj1684 [Usaco2005 Oct]Close Encounter
Description Lacking even a fifth grade education, the cows are having trouble with a fraction proble ...
- bzoj:1685 [Usaco2005 Oct]Allowance 津贴
Description As a reward for record milk production, Farmer John has decided to start paying Bessie t ...
- 【BZOJ】1685: [Usaco2005 Oct]Allowance 津贴(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1685 由于每个小的都能整除大的,那么我们在取完大的以后(不超过c)后,再取一个最小的数来补充,可以证 ...
- 【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)( ...
- BZOJ 1685 [Usaco2005 Oct]Allowance 津贴:贪心【给硬币问题】
题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1333 题意: 有n种不同币值的硬币,并保证大币值一定是小币值的倍数. 每种硬币的币值为 ...
随机推荐
- JVM(二):Java中的语法糖
JVM(二):Java中的语法糖 上文讲到在语义分析中会对Java中的语法糖进行解糖操作,因此本文就主要讲述一下Java中有哪些语法糖,每个语法糖在解糖过后的原始代码,以及这些语法糖背后的逻辑. 语法 ...
- Redis集群方案之主从复制(待实践)
Redis有主从复制的功能,一台主可以有多台从,从还可以有多台从,但是从只能有一个主.并且在从写入的数据不会复制到主. 配置 在Redis中,要实现主从复制架构非常简单,只需要在从数据库的配置文件中加 ...
- SaltStack学习系列之Nginx部署
目录结构 |-- nginx | |-- files #放包文件的 | | |-- admin_22.conf | | |-- fastcgi_params | | |-- jim_fix_param ...
- EEPlat的控制器概念
控制器是EEPlat平台界面层部分的核心概念.平台中界面展示都是通过平台的各种控制器综合控制输出的. EEPlat平台的界面层模型採用了HMVC模式.HMVC模式的採用使得EEPlat平台界面层可以实 ...
- Python随机播放电脑里的音乐
就是找到硬盘中全部的MP3文件和wma文件.再随机打开当中的一个. import os,random disk=['D','E','F','G','H'] def search_file(filena ...
- [git push] rejecteded 问题的解决方法
错误信息: hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart ...
- 关于appcompat_v7的说明
http://blog.csdn.net/crazykbc/article/details/21553699 问题描述: 使用eclipse创建一个Android项目时,发现project列表中会多创 ...
- JavaScript基础 -- 焦点图轮播(转载)
首先将HTML结构搭建好: <div id="container"> <div id="list" style="left: -60 ...
- 如何理解scrapy Selector
1 scrapy Selector是什么 Selector对象本质上是对DOM tree的子树的抽象,这种抽象的目的是用于定位我们感兴趣的node.比如某次http response是一棵完整的DOM ...
- Android系统定制----删除系统锁屏功能【转】
本文转载自:http://blog.csdn.net/morixinguan/article/details/56675914 frameworks/base/packages/SettingsPro ...