传送门: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. Thymeleaf 常用th标签基础整理

    (一)Thymeleaf 是个什么?      简单说, Thymeleaf 是一个跟 Velocity.FreeMarker 类似的模板引擎,它可以完全替代 JSP .相较与其他的模板引擎,它有如下 ...

  2. Python 3基础教程28-内置函数

    本文介绍Python中的内置函数,Python中有很多内置的,功能强大的函数,可以帮我们解决很多问题,有些方法,根本不需要你去再次编写实现函数,你直接调用就可以.在这之前,需要介绍下,如何在windo ...

  3. 第九篇 Python数据类型之集合

    集合 set 写在最前,必须要会的:1.长度len2.成员运算in和not in3.|合集4.&交集5.-差集6.^对称差集7.==8.父集:>,>= 9.子集:<,< ...

  4. Structure From Motion(SFM,从运动恢复结构)

    Structure From Motion(SFM,从运动恢复结构) 阅读相关文献: Wu et al. Multicore Bundle Adjustment Agarwal et. al. Bun ...

  5. 线段树——hdu1754I Hate It

    一.题目回顾 题目链接:I Hate It Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感.不管你喜不喜欢 ...

  6. IDEA使用maven构建时控制台中文乱码的解决办法

    使用maven clean install 项目时控制台中文乱码,解决办法如下: Setting->maven->runner VMoptions: -Dfile.encoding=UTF ...

  7. Mac下使用Charles抓包Android

    原文地址:http://fanjiajia.cn/2018/11/21/Mac%E4%B8%8B%E4%BD%BF%E7%94%A8Charles%E6%8A%93%E5%8C%85Android/ ...

  8. To Chromium之版本管理

    Git. 1.由于想直接submit到Chromium的官方Branch需要申请权限,目前拿不到,所以打算snapshot一个chromium版本. 本地搭建一个git的server/client,方 ...

  9. [剑指Offer] 19.顺时针打印矩阵

    [思路]本题关键在于 右->左 和 下->上 两个循环体中的判断条件,即判断是否重复打印. class Solution { public: vector<int> print ...

  10. 【SQLAlchemy】SQLAlchemy技术文档(中文版)(中)

    10.建立联系(外键) 是时候考虑怎样映射和查询一个和Users表关联的第二张表了.假设我们系统的用户可以存储任意数量的email地址.我们需要定义一个新表Address与User相关联. from ...