传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1577

【题解】

我们把每坨奶牛按s排个序。

对于每坨奶牛,如果车上有空位置就塞。

否则,看下车上是否有奶牛的e值比他大,就把这个奶牛扔下去(当做没上过车),把新的奶牛拉上来(因为更大的区间显然不优)。

每次操作前遍历set看是否有奶牛到站了,下车即可。

最后记得加上s.size。时间复杂度O(nclogn)

# include <set>
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + ;
const int mod = 1e9+; # define RG register
# define ST static int n, m, c;
struct pa {
int s, e, num;
pa() {}
pa(int s, int e, int num) : s(s), e(e), num(num) {}
friend bool operator <(pa a, pa b) {
return a.e < b.e;
}
}p[M]; inline bool cmp(pa a, pa b) {
return a.s < b.s || (a.s == b.s && a.e < b.e);
} multiset<pa> s;
multiset<pa>::iterator it, tem; int main() {
cin >> m >> n >> c;
for (int i=; i<=m; ++i) scanf("%d%d%d", &p[i].s, &p[i].e, &p[i].num);
sort(p+, p+m+, cmp);
int cnt = ;
for (int i=; i<=m; ++i) {
for (it = s.begin(); it != s.end();) {
if((*it).e <= p[i].s) {
cnt ++;
tem = it;
++it;
s.erase(tem);
} else ++it;
}
if(s.size() < c) {
while(p[i].num && s.size() < c) {
s.insert(p[i]);
--p[i].num;
}
}
if(p[i].num) {
it = --s.end();
while(p[i].num && (*it).e > p[i].e) {
s.erase(it);
s.insert(p[i]);
--p[i].num;
it = --s.end();
}
}
// for (it = s.begin(); it != s.end(); ++it) cout << (*it).s << ' ' << (*it).e << ' ' << (*it).num << endl;
// cout << i << ' ' << s.size() << endl;
}
cout << cnt + s.size();
return ;
}

bzoj1577 [Usaco2009 Feb]庙会捷运Fair Shuttle的更多相关文章

  1. 【贪心】bzoj1577: [Usaco2009 Feb]庙会捷运Fair Shuttle

    一类经典的线段贪心 Description 公交车一共经过N(1<=N<=20000)个站点,从站点1一直驶到站点N.K(1<=K<=50000)群奶牛希望搭乘这辆公交车.第i ...

  2. [bzoj1577][Usaco2009 Feb]庙会捷运Fair Shuttle_贪心_线段树

    庙会捷运 Fair Shuttle bzoj-1577 Usaco-2009 Feb 题目大意:有一辆公交车从1走到n.有m群奶牛从$S_i$到$E_i$,第i群奶牛有$W_i$只.车有一个容量c.问 ...

  3. bzoj 1577: [Usaco2009 Feb]庙会捷运Fair Shuttle——小根堆+大根堆+贪心

    Description 公交车一共经过N(1<=N<=20000)个站点,从站点1一直驶到站点N.K(1<=K<=50000)群奶牛希望搭乘这辆公交车.第i群牛一共有Mi(1& ...

  4. [Usaco2009 Feb]庙会捷运Fair Shuttle

    Description 公交车一共经过N(1<=N<=20000)个站点,从站点1一直驶到站点N.K(1<=K<=50000)群奶牛希望搭乘这辆公交车.第i群牛一共有Mi(1& ...

  5. BZOJ 1577: [Usaco2009 Feb]庙会捷运Fair Shuttle 线段树 + 贪心

    escription 公交车一共经过N(1<=N<=20000)个站点,从站点1一直驶到站点N.K(1<=K<=50000)群奶牛希望搭乘这辆公交车.第i群牛一共有Mi(1&l ...

  6. 【BZOJ】1577: [Usaco2009 Feb]庙会捷运Fair Shuttle

    [题意]公车从1开到n,有k群牛想从一个点到达另一个点,公车最多乘坐c个人,牛群可以拆散,问最多载多少牛到达目的地. [算法]贪心+堆 [题解]线段和点的贪心,一般有按左端点排序和按右端点排序两种方法 ...

  7. bzoj 1577: [Usaco2009 Feb]庙会捷运Fair Shuttle【贪心+线段树】

    按结束时间排序,然后开个线段树,按照排序后的牛群贪心的选 贪心的依据是选哪头牛都是选,不如给后面的多省一点空间 #include<iostream> #include<cstdio& ...

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

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

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

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

随机推荐

  1. Linux/CentOS防CC攻击脚本

    #!/bin/sh cd /var/log/httpd/ cat access_log|awk > a cp /dev/null access_log cp /dev/null error_lo ...

  2. android get cpu rate

    public static int getProcessCpuRate() { try { RandomAccessFile reader = new RandomAccessFile("/ ...

  3. Android ImageSwitcher 配合Picasso解决内存溢出(OOM)问题

    最近项目中用到了 ImageSwitcher 来实现图片切换,使用起来很简单,但发现当图片比较大(超过了3M)时,程序出现了内存溢出(OOM)问题而崩溃了. 原因就是图片太大了,显示到 ImageVi ...

  4. iOS-读写plist文件

    读写plist文件 问题,我有一个plist文件,表示56个民族的,但是里面保存的字典,我想转换成一个数组 好的,那么就先遍历这个plist,然后将结果保存到一个数组中,这里出现的一个问题就是C语言字 ...

  5. Python 3基础教程22-单个列表操作

    本文来介绍列表的操作,先看看单个列表的操作,列表有多个方法.以下多行代码,建议你写一个方法,测试运行一个方法,不然看起来很乱. # 元组操作 x = [5,6,2,1,6,7,2,7,9] # app ...

  6. python3.6 新特性学习

    #支持类型提示 typing { def greeting(name: str) -> str: return 'Hello ' + name #在函数greeting中,参数名称的类型为str ...

  7. 九度OJ--1165(C++)

    #include <iostream>#include <string>#include <vector> using namespace std; int mai ...

  8. skip-grant-tables 修改linux的mysql忘记root密码

    skip-grant-tables 修改linux的mysql忘记root密码 今天修改mysql中的admin用户权限,在执行update user set host =' %' where use ...

  9. Extjs的API阅读方式(整理)

    原文链接:http://www.cnblogs.com/gaojun/archive/2013/05/28/3103908.html

  10. P1650 田忌赛马

    题目描述 我国历史上有个著名的故事: 那是在2300年以前.齐国的大将军田忌喜欢赛马.他经常和齐王赛马.他和齐王都有三匹马:常规马,上级马,超级马.一共赛三局,每局的胜者可以从负者这里取得200银币. ...