线段树.. -------------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream>   #define rep( i , n ) for( int i = 0 ; i < n ; i++ ) #define…
题目 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 553  Solved: 307[Submit][Status] Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some preci…
1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 566  Solved: 314[Submit][Status] Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise…
http://www.lydsy.com/JudgeOnline/problem.php?id=1651 很奇妙.. 我们发现,每一时刻的重叠数选最大的就是答案.... orz 那么我们可以线段树维护每个点的次数... 然后就ok了.. 第二种做法:用前缀和来维护即可... 线段树: #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <ios…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1651 题意: 给你n个线段[a,b],问你这些线段重叠最多的地方有几层. 题解: 先将线段按左端点a升序排序. 开一个优先队列q(升序排序),里面存线段的右端点b. 枚举线段i,然后: (1)将q中所有小于a[i]的元素弹出. (2)插入b[i]. (3)更新ans = max(ans,q.size()) AC Code: #include <iostream> #include &l…
这个题方法还挺多的,不过洛谷上要输出方案所以用堆最方便 先按起始时间从小到大排序. 我用的是greater重定义优先队列(小根堆).用pair存牛棚用完时间(first)和牛棚编号(second),每次查看队首的first是否比当前牛的起始时间早,是则弹出队首记录当前牛的答案,再把新的pair放进去,否则增加牛棚,同样要塞进队里 #include<iostream> #include<cstdio> #include<algorithm> #include<que…
1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 509  Solved: 280[Submit][Status] Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise…
Stall Reservations 原文是English,这里直接上中文吧 Descriptions: 这里有N只 (1 <= N <= 50,000) 挑剔的奶牛! 他们如此挑剔以致于必须在[A,B ]的时间内产奶(1 <= A <= B <= 1,000,000)当然, FJ必须为他们创造一个决定挤奶时间的系统.当然,没有牛想与其他奶牛分享这一时光 帮助FJ做以下事: 使每只牛都有专属时间的最小牛棚数 每只牛在哪个牛棚 也许有很多可行解.输出一种即可,采用SPJ Inp…
[USACO06FEB] Stall Reservations 贪心 \(n\)头牛,每头牛占用时间区间\([l_i,r_i]\),一个牛棚每个时间点只能被一头牛占用,问最少新建多少个牛棚,并且每头牛在哪个牛棚里? 比较巧的\(O(n)\)扫一遍做法,用一个小跟堆维护所有牛棚最后一个牛占用的时间(即\(r_i\)),贪心的想,如果最先结束的那个牛棚都不能满足当前牛,那么我们只能新开一个牛棚,并继续维护小根堆:如果那个牛棚满足,那么这个牛就去那个牛棚,更新当前牛棚最后占用时间. #include…
[USACO06FEB]摊位预订Stall Reservations 题目描述 Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise time interval A..B (1 <= A <= B <= 1,000,000), which includes both times A and B. Obviou…