题目描述

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,彼

此用空格隔开。

输出格式:

【输出】

第一行:可以坐班车的奶牛的最大头数。

输入输出样例

输入样例#1:

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
输出样例#1:

10

说明

【样例说明】

班车可以把2头奶牛从1送到5,3头奶牛从5送到8,2头奶牛从8送到14,1头

奶牛从9送到12,1头奶牛从13送到14,1头奶牛从14送到15。

题解:贪心+线段树

按结束点排序 放尽量多的奶牛。

每次要查询区间最大值 和修改区间最大值 需要线段树维护

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define maxn 200005
using namespace std; int k,n,m,ans;
struct Tree{
int l,r,sum,s;
}tr[maxn<<];
struct GS{
int x,y,c;
bool operator < (const GS &a) const{
return y<a.y;
}
}a[maxn*]; void pushup(int rt){
tr[rt].sum=max(tr[rt<<].sum,tr[rt<<|].sum);
return;
} void pushdown(int rt){
if(!tr[rt].s)return;
tr[rt<<].s+=tr[rt].s;tr[rt<<|].s+=tr[rt].s;
tr[rt<<].sum+=tr[rt].s;tr[rt<<|].sum+=tr[rt].s;
tr[rt].s=;
} void build(int rt,int l,int r){
tr[rt].l=l;tr[rt].r=r;
if(l==r)return;
int mid=(l+r)>>;
build(rt<<,l,mid);
build(rt<<|,mid+,r);
} int query(int rt,int l,int r,int qx,int qy){
pushdown(rt);
if(l>=qx&&r<=qy){
return tr[rt].sum;
}
int mid=(l+r)>>;
if(qy<=mid)return query(rt<<,l,mid,qx,qy);
else if(qx>mid)return query(rt<<|,mid+,r,qx,qy);
else return max(query(rt<<,l,mid,qx,mid),query(rt<<|,mid+,r,mid+,qy));
} void change(int rt,int l,int r,int qx,int qy,int z){
pushdown(rt);
if(l>=qx&&r<=qy){
tr[rt].sum+=z;
tr[rt].s+=z;
return;
}
int mid=(l+r)>>;
if(qy<=mid)change(rt<<,l,mid,qx,qy,z);
else if(qx>mid)change(rt<<|,mid+,r,qx,qy,z);
else change(rt<<,l,mid,qx,mid,z),change(rt<<|,mid+,r,mid+,qy,z);
pushup(rt);
} int main(){
scanf("%d%d%d",&k,&n,&m);
for(int i=;i<=k;i++)scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].c);
sort(a+,a+k+);
for(int i=;i<=k;i++){
int p=min(a[i].c,m-query(,,n,a[i].x,a[i].y-));
if(p){
ans+=p;
change(,,n,a[i].x,a[i].y-,p);
}
}
printf("%d\n",ans);
return ;
}

P1607 [USACO09FEB]庙会班车Fair Shuttle的更多相关文章

  1. 洛谷 P1607 [USACO09FEB]庙会班车Fair Shuttle 解题报告

    P1607 [USACO09FEB]庙会班车Fair Shuttle 题目描述 Although Farmer John has no problems walking around the fair ...

  2. 洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle

    P1607 [USACO09FEB]庙会班车Fair Shuttle 题目描述 Although Farmer John has no problems walking around the fair ...

  3. 【贪心】洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle 题解

        不是很容易写出正解的贪心问题. 题目描述 Although Farmer John has no problems walking around the fair to collect pri ...

  4. 线段树【p1607】[USACO09FEB]庙会班车Fair Shuttle

    Description 逛逛集市,兑兑奖品,看看节目对农夫约翰来说不算什么,可是他的奶牛们非常缺乏锻炼--如果要逛完一整天的集市,他们一定会筋疲力尽的.所以为了让奶牛们也能愉快地逛集市,约翰准备让奶牛 ...

  5. [USACO09FEB]庙会班车Fair Shuttle 线段树维护maxx&&贪心

    题目描述 Although Farmer John has no problems walking around the fair to collect prizes or see the shows ...

  6. [USACO09FEB]庙会班车Fair Shuttle

    题目描述 逛逛集市,兑兑奖品,看看节目对农夫约翰来说不算什么,可是他的奶牛们非常缺乏锻炼——如果要逛完一整天的集市,他们一定会筋疲力尽的.所以为了让奶牛们也能愉快地逛集市,约翰准备让奶牛们在集市上以车 ...

  7. 【USACO09FEB】 庙会班车 Fair Shuttle 贪心+线段树

    Although Farmer John has no problems walking around the fair to collect prizes or see the shows, his ...

  8. 【Luogu】P1607庙会班车Fair Shuttle(线段树+贪心)

    我不会做贪心题啊……贪心题啊……题啊……啊…… 我真TM菜爆了啊…… 这题就像凌乱的yyy一样,把终点排序,终点相同的按起点排序.然后维护一个查询最大值的线段树.对于一个区间[l,r],如果这个区间已 ...

  9. <USACO09FEB>庙会捷运Fair Shuttleの思路

    一个没有被我成功证明的 贪心 但是 ac了的 别人排序都是排终点.但我的排终点错了emm排起点才对qvq 有没有人友情看看怎么证(没有 #include<cstdio> #include& ...

随机推荐

  1. Java获取字符串的CRC8校验码(由C程序的代码修改为了Java代码)

    CRC8算法请百度,我也不懂,这里只是把自己运行成功的结构贴出来了.方法CRC8_Tab这里没有处理,因为我的程序中没有用到. package com.crc; public class CCRC8_ ...

  2. Entity Framework 4.1:复杂类型

    这篇文章将讨论复杂类型. 默认情况下,EF4.1 将类映射到表,这是约定,但是有时候,我们需要模型比表的粒度更细一些. 地址是一个典型的例子,看一下下面的客户类. )] publicstring St ...

  3. RedisTemplate访问Redis数据结构(介绍和常用命令)

    Redis 数据结构简介 Redis 可以存储键与5种不同数据结构类型之间的映射,这5种数据结构类型分别为String(字符串).List(列表).Set(集合).Hash(散列)和 Zset(有序集 ...

  4. 九度OJ 1204:农夫、羊、菜和狼的故事 (遍历、BFS)

    时间限制:1 秒 内存限制:32 兆 特殊判题:是 提交:744 解决:502 题目描述: 有一个农夫带一只羊.一筐菜和一只狼过河. 果没有农夫看管,则狼要吃羊,羊要吃菜. 但是船很小,只够农夫带一样 ...

  5. ibatis实现Iterate的使用 (转)

    <iterate         property="" /*可选,              从传入的参数集合中使用属性名去获取值,              这个必须是一 ...

  6. Surpassing Human-Level Face Verification Performance on LFW with GaussianFace

    Face verification remains a challenging problem in very complex conditions with large variations suc ...

  7. Python菜鸟之路:sqlalchemy/paramiko进阶

    前言:ORM中的两种创建方式 数据库优先:指的是先创建数据库,包括表和字段的建立,然后根据数据库生成ORM的代码,它是先创建数据库,再创建相关程序代码 代码优先:就是先写代码,然后根据代码去生成数据库 ...

  8. redis持久化AOF详细操作步骤

    1.切换到redis目录下面,创建文件 s3-redis.conf 2.编辑文件s3-redis.conf 3.终止当前redis服务端 4.登录redis客户端失败,说明服务端已停止 5.重启red ...

  9. Python 面试题(下)

    接上篇. 网络 1 三次握手 客户端通过向服务器端发送一个SYN来创建一个主动打开,作为三路握手的一部分.客户端把这段连接的序号设定为随机数 A. 服务器端应当为一个合法的SYN回送一个SYN/ACK ...

  10. linux shell 中数组使用方法介绍

    linux shell在编程方面比windows 批处理强大太多,不管是在循环.运算.已经数据类型方面都是不能比較的. 以下是个人在使用时候,对它在数组方面一些操作进行的总结. 1.数组定义 [che ...