Description
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
Input
Lines 2..N+1: Line i+1 describes cow i's milking interval with two space-separated integers.
Output
Lines 2..N+1: Line i+1 describes the stall to which cow i will be assigned for her milking period.
Sample Input
5 1 10 2 4 3 6 5 8 4 7
Sample Output
4 1 2 3 2 4
Hint
Here's a graphical schedule for this output:
Time 1 2 3 4 5 6 7 8 9 10Other outputs using the same number of stalls are possible.
Stall 1 c1>>>>>>>>>>>>>>>>>>>>>>>>>>>
Stall 2 .. c2>>>>>> c4>>>>>>>>> .. ..
Stall 3 .. .. c3>>>>>>>>> .. .. .. ..
Stall 4 .. .. .. c5>>>>>>>>> .. .. ..
很多牛,要吃草,每头牛吃草时间不一样,一个食槽时间段内只能给一头牛用,求最少多少个槽子。想法就是先按开始吃的时间排序,然后访问插入食槽,如果不能插入,就另开一个。二重循环,果断超时。然而我并不会队列,于是- -看了题解,学习了队列,并且又写了一个队列巩固一下。
#include
#include
#include
#include
#include
using namespace std;
struct Cow{
}cow[50005];
int leap[50005], stall[500005];
bool cmp(const Cow&a, const Cow&b)
{
}
priority_queueq;
int main()
{
}