BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
来源:互联网 发布:背锅侠网络意思 编辑:程序博客网 时间:2024/05/17 07:58
Description
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. Obviously, FJ must create a reservation system to determine which stall each cow can be assigned for her milking time. Of course, no cow will share such a private moment with other cows. Help FJ by determining: * The minimum number of stalls required in the barn so that each cow can have her private milking period * An assignment of cows to these stalls over time
有N头牛,每头牛有个喝水时间,这段时间它将专用一个Stall 现在给出每头牛的喝水时间段,问至少要多少个Stall才能满足它们的要求
Input
* Line 1: A single integer, N
* Lines 2..N+1: Line i+1 describes cow i's milking interval with two space-separated integers.
Output
* Line 1: The minimum number of stalls the barn must have.
* Lines 2..N+1: Line i+1 describes the stall to which cow i will be assigned for her milking period.
Sample Input
1 10
2 4
3 6
5 8
4 7
Sample Output
OUTPUT DETAILS:
Here's a graphical schedule for this output:
Time 1 2 3 4 5 6 7 8 9 10
Stall 1 c1>>>>>>>>>>>>>>>>>>>>>>>>>>>
Stall 2 .. c2>>>>>> c4>>>>>>>>> .. ..
Stall 3 .. .. c3>>>>>>>>> .. .. .. ..
Stall 4 .. .. .. c5>>>>>>>>> .. .. ..
Other outputs using the same number of stalls are possible.
HINT
不妨试下这个数据,对于按结束点SORT,再GREEDY的做法 1 3 5 7 6 9 10 11 8 12 4 13 正确的输出应该是3
题解
每个时间点需要牛棚的数量取决于有多少覆盖它的区间,差分序列即可。
#include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<cmath> #include<algorithm> #define inf 1<<30 #define ll long long using namespace std; int n,a[1000010],ans; int main() { scanf("%d",&n); int i,x,y; for(i=1;i<=n;i++) {scanf("%d%d",&x,&y); a[x]++; a[y+1]--; } for(i=1;i<=1000000;i++) {a[i]=a[i-1]+a[i]; if(a[i]>ans) ans=a[i]; } printf("%d",ans); return 0; }
- BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
- BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
- 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
- 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
- bzoj1651[Usaco2006 Feb]Stall Reservations 专用牛棚
- [BZOJ1651] [Usaco2006 Feb]Stall Reservations 专用牛棚
- bzoj1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
- bzoj1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
- BZOJ1651--[Usaco2006 Feb]Stall Reservations 专用牛棚
- [Usaco2006 Feb]Stall Reservations 专用牛棚
- [bzoj1651][Usaco2006 Feb]Stall Reservations 专用牛棚
- bzoj 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 (线段树)
- |BZOJ 1651|差分序列|[Usaco2006 Feb]Stall Reservations 专用牛棚
- 51nod 1428 && bzoj 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
- [BZOJ1651][Usaco2006 Feb]Stall Reservations 专用牛棚(线段树)
- 1651: [Usaco2006 Feb]专用牛棚[经典] 多个区间不相交
- BZOJ1651Stall Reservations 专用牛棚
- Stall Reservations
- linux 学习理解 & 命令详解
- POJ 3468 A Simple Problem with Integers 【线段树,区间更新】
- 单例模式的七种写法
- UE注册
- POJ1083
- BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
- Java JDK8 Windows XP安装与“无... RegDeleteKeyExA 于... ADVAPI32.dll”的解决
- pdf转换成excel转换器怎么用
- 单例模式的七种写法
- neu1458 方格取数 dp解法
- CodeForces 69D Dot (博弈+记忆化)
- POJ 2524 Ubiquitous Religions
- perl解析语法
- JSF中h:message 和h:messages 的区别