Stall Reservations
Description
Oh those picky \(N (1 \le N \le 5\times 10^4)\) cows! They are so picky that each one will only be milked over some precise time interval \(A..B (1 \le A \le B \le 10^6)\), 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
Many answers are correct for each test dataset; a program will grade your answer.
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.
you should only print the mininum number because special judge is not supported here
Simplified
给出N条线段的左端点和右端点,将其不重叠地放在数轴上,求至少需要几个数轴。
重叠的定义为两根线段有公共点。
Samples
Sample #1
Input
5
1 10
2 4
3 6
5 8
4 7
Output
4
Source
算法竞赛进阶指南 POJ
信息
- ID
- 1025
- 难度
- 9
- 分类
- (无)
- 标签
- (无)
- 递交数
- 2
- 已通过
- 1
- 通过率
- 50%
- 上传者