POJ 3190 Stall Reservations (Greedy)
Stall Reservations
Time Limit:1000 MS |
|
Memory Limit:65536 K |
Total Submissions:3590 |
|
Accepted:1284 |
|
Special Judge |
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 .. B (1 <= A <= B <= 1,000,000), where des both times A and B. obviusly, 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 stils required in the barn so that each cow can have her private milking periodAn assignment of cows to these stils over time when 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 stallthe 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
51 102 43 65 84 7
Sample Output
412324
Hint
Explanation of the sample:
Here's a graphical schedule for this output:
Time 1 2 3 4 5 6 7 8 9 10Stall 1 c1>>>>>>>>>>>>>>>>>>>>>>>>>>>Stall 2 .. c2>>>>>> c4>>>>>>>>> .. ..Stall 3 .. .. c3>>>>>>>>> .. .. .. ..Stall 4 .. .. .. c5>>>>>>>>> .. .. ..
Other outputs using the same number of stils are possible.
Source
USACO 2006 February Silver
#include
#include
#include
#include#include
#include
#include
#include
#include
#include
#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define epst 1e-8typedef __int64 ll;#define fre(i,a,b) for(i = a; i
= a;i--)#define mem(t, v) memset ((t) , v, sizeof(t))#define ssf(n) scanf("%s", n)#define sf(n) scanf("%d", &n)#define sff(a,b) scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pf printf#define bug pf("Hi\n")using namespace std;#define INF 0x3f3f3f3f#define N 50005struct stud{ int x,y; int pos; bool operator <(const stud d) const {return y>d.y; }}f[N];int ans[N];int k;priority_queue
q;int n;int cmp(stud a,stud b){if(a.x==b.x) return a.y