洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle
P1607 [USACO09FEB]庙会班车Fair Shuttle
题目描述
Although Farmer John has no problems walking around the fair to collect prizes or see the shows, his cows are not in such good shape; a full day of walking around the fair leaves them exhausted. To help them enjoy the fair, FJ has arranged for a shuttle truck to take the cows from place to place in the fairgrounds.
FJ couldn't afford a really great shuttle, so the shuttle he rented traverses its route only once (!) and makes N (1 <= N <= 20,000) stops (conveniently numbered 1..N) along its path. A total of K (1 <= K <= 50,000) groups of cows conveniently numbered 1..K wish to use the shuttle, each of the M_i (1 <= M_i <= N) cows in group i wanting to ride from one stop S_i (1 <= S_i < E_i) to another stop E_i (S_i < E_i <= N) farther along the route.
The shuttle might not be able to pick up an entire group of cows (since it has limited capacity) but can pick up partial groups as appropriate.
Given the capacity C (1 <= C <= 100) of the shuttle truck and the descriptions of the groups of cows that want to visit various sites at the fair, determine the maximum number of cows that can ride the shuttle during the fair.
逛逛集市,兑兑奖品,看看节目对农夫约翰来说不算什么,可是他的奶牛们非常缺乏锻炼——如果要逛完一整天的集市,他们一定会筋疲力尽的。所以为了让奶牛们也能愉快地逛集市,约翰准备让奶牛们在集市上以车代步。但是,约翰木有钱,他租来的班车只能在集市上沿直线跑一次,而且只能停靠N(1 ≤N≤20000)个地点(所有地点都以1到N之间的一个数字来表示)。现在奶牛们分成K(1≤K≤50000)个小组,第i 组有Mi(1 ≤Mi≤N)头奶牛,他们希望从Si跑到Ti(1 ≤Si<Ti≤N)。
由于班车容量有限,可能载不下所有想乘车的奶牛们,此时也允许小里的一部分奶牛分开乘坐班车。约翰经过调查得知班车的容量是C(1≤C≤100),请你帮助约翰计划一个尽可能满足更多奶牛愿望的方案。
输入输出格式
输入格式:
【输入】
第一行:包括三个整数:K,N和C,彼此用空格隔开。
第二行到K+1行:在第i+1行,将会告诉你第i组奶牛的信息:Si,Ei和Mi,彼
此用空格隔开。
输出格式:
【输出】
第一行:可以坐班车的奶牛的最大头数。
输入输出样例
8 15 3
1 5 2
13 14 1
5 8 3
8 14 2
14 15 1
9 12 1
12 15 2
4 6 1
10
说明
【样例说明】
班车可以把2头奶牛从1送到5,3头奶牛从5送到8,2头奶牛从8送到14,1头
奶牛从9送到12,1头奶牛从13送到14,1头奶牛从14送到15。
/*
优先选结束位置最小的,能选就选,然后就是怎么判断是否可以选,那么可以选的条件是这个组的[L,R]之间的最大值加上这个组的人不会超过最大容量C,所以维护一个区间最大值就好,如果塞不进,能塞多少是多少,本蒟蒻用的是线段树,然后每一次选完后就在线段树中[L,R-1] 加上这个组的人数即可
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#define maxn 50010
using namespace std;
int n,m,c,opl,opr,opv,ans;
struct node{
int l,r,v;
bool operator < (const node b)const{
if(r!=b.r)return r<b.r;
return l>b.l;
}
}a[maxn];
struct Node{
int l,r,v,lazy;
}tr[maxn*];
void build(int l,int r,int k){
tr[k].l=l;tr[k].r=r;
if(l==r)return;
int mid=(l+r)>>;
build(l,mid,k<<);
build(mid+,r,k<<|);
}
void updata(int k){
tr[k<<].lazy+=tr[k].lazy;
tr[k<<|].lazy+=tr[k].lazy;
tr[k<<].v+=tr[k].lazy;
tr[k<<|].v+=tr[k].lazy;
tr[k].lazy=;
}
int query(int l,int r,int opl,int opr,int k){
if(l>=opl&&r<=opr)return tr[k].v;
if(tr[k].lazy)updata(k);
int mid=(l+r)>>,res=;
if(opl<=mid)res=max(res,query(l,mid,opl,opr,k<<));
if(opr>mid)res=max(res,query(mid+,r,opl,opr,k<<|));
tr[k].v=max(tr[k<<].v,tr[k<<|].v);
return res;
}
void change(int l,int r,int opl,int opr,int k,int v){
if(l>=opl&&r<=opr){
tr[k].v+=v;
tr[k].lazy+=opv;
return;
}
if(tr[k].v)updata(k);
int mid=(l+r)>>;
if(opl<=mid)change(l,mid,opl,opr,k<<,v);
if(opr>mid)change(mid+,r,opl,opr,k<<|,v);
tr[k].v=max(tr[k<<].v,tr[k<<|].v);
}
int main(){
freopen("Cola.txt","r",stdin);
scanf("%d%d%d",&m,&n,&c);
build(,n,);
for(int i=;i<=m;i++)scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].v);
sort(a+,a+m+);
for(int i=;i<=m;i++){
opl=a[i].l,opr=a[i].r;
int mx=query(,n,opl,opr,);
if(mx>=c)continue;
if(mx+a[i].v<=c)opv=a[i].v;
else opv=c-mx;
ans+=opv;
opr--;
change(,n,opl,opr,,opv);
}
printf("%d",ans);
}
洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle的更多相关文章
- 洛谷 P1607 [USACO09FEB]庙会班车Fair Shuttle 解题报告
P1607 [USACO09FEB]庙会班车Fair Shuttle 题目描述 Although Farmer John has no problems walking around the fair ...
- 【贪心】洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle 题解
不是很容易写出正解的贪心问题. 题目描述 Although Farmer John has no problems walking around the fair to collect pri ...
- P1607 [USACO09FEB]庙会班车Fair Shuttle
题目描述 Although Farmer John has no problems walking around the fair to collect prizes or see the shows ...
- 线段树【p1607】[USACO09FEB]庙会班车Fair Shuttle
Description 逛逛集市,兑兑奖品,看看节目对农夫约翰来说不算什么,可是他的奶牛们非常缺乏锻炼--如果要逛完一整天的集市,他们一定会筋疲力尽的.所以为了让奶牛们也能愉快地逛集市,约翰准备让奶牛 ...
- [USACO09FEB]庙会班车Fair Shuttle 线段树维护maxx&&贪心
题目描述 Although Farmer John has no problems walking around the fair to collect prizes or see the shows ...
- [USACO09FEB]庙会班车Fair Shuttle
题目描述 逛逛集市,兑兑奖品,看看节目对农夫约翰来说不算什么,可是他的奶牛们非常缺乏锻炼——如果要逛完一整天的集市,他们一定会筋疲力尽的.所以为了让奶牛们也能愉快地逛集市,约翰准备让奶牛们在集市上以车 ...
- 【USACO09FEB】 庙会班车 Fair Shuttle 贪心+线段树
Although Farmer John has no problems walking around the fair to collect prizes or see the shows, his ...
- 【Luogu】P1607庙会班车Fair Shuttle(线段树+贪心)
我不会做贪心题啊……贪心题啊……题啊……啊…… 我真TM菜爆了啊…… 这题就像凌乱的yyy一样,把终点排序,终点相同的按起点排序.然后维护一个查询最大值的线段树.对于一个区间[l,r],如果这个区间已 ...
- [洛谷P1607] 庙会班车
题目描述 Although Farmer John has no problems walking around the fair to collect prizes or see the shows ...
随机推荐
- 分享知识-快乐自己:SSH 整合 Demo
楼主A: XML 版 SSH整合Demo https://github.com/MlqBeginner/BlogGardenWarehouse/blob/master/SSH%E6%95%B4%E5% ...
- hdu 2041 超级楼梯(简单dp)
超级楼梯 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- C趣味题目
http://www.cnblogs.com/lua5/archive/2010/12/05/1896755.html c语言趣味题目 http://www.cppblog.com/OnTheWa ...
- php将一个二维数组按照某个字段值合并成一维数组,如果有重复则将重复的合并成二维数组
版权声明:本文为博主原创文章,未经博主允许不得转载. 最近工作中碰到一个问题,用PHP将一个二维数组按照二维数组中的各个项中的某个特定字段值合并成一维数组,如果有重复则将重复的合并成二维数组,生成的二 ...
- docker 基本概念
image 操作系统 应用 registeries image 的远程仓库 containers 类似一个目录,一个容器包含了 应用运行所需要的一切东西, 容器之间互相独立 image包换一系列的层, ...
- (转)#ifndef的用法
原文链接:http://wenku.baidu.com/link?url=c4doqVo3U429RkwTN5eaJIfD2rEu-1bLKKQXuqO8drmL359PhUjVmzC7P94wBY9 ...
- 07 - Django应用第四步
知识点 1) 表单的编写 CSRF问题 forloop.counter 2) 视图函数的知识 GET和POST HttpResponseRedirect的使用 reverse的使用 3) 通用视图 C ...
- bzoj3573米特运输
题意: 给定一棵树上的边和点权 改动点权使得每个父节点u容量为子节点容量的d[u](子节点个数)倍 考察点: 1.这是一道语文题 2.点权很大 直接算会爆 有一种优化办法:取log(醉 这是什么优化) ...
- Sqlite表结构读取工具,word批量转html,在线云剪贴板,文件批量提取工具;
工欲善其事必先利其器,本周为您推荐工具排行 Sqlite表结构读取工具,word批量转html,在线云剪贴板,文件批量提取工具: 本周我们又要发干货了,准备好接受了吗? 为什么是干货,就是因为 ...
- bzoj 4631: 踩气球 线段树
题目: Description 六一儿童节到了, SHUXK 被迫陪着M个熊孩子玩一个无聊的游戏:有N个盒子从左到右排成一排,第i个盒子里装着Ai个气球. SHUXK 要进行Q次操作,每次从某一个盒子 ...