# BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚

## 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 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 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

## 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.

5
1 10
2 4
3 6
5 8
4 7

## Sample Output

4

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

 1 /*Author:WNJXYK*/
2 #include<cstdio>
3 using namespace std;
4
5 #define LL long long
6 #define Inf 2147483647
7 #define InfL 10000000000LL
8
9 inline int abs(int x){if (x<0) return -x;return x;}
10 inline int abs(LL x){if (x<0) return -x;return x;}
11 inline void swap(int &x,int &y){int tmp=x;x=y;y=tmp;}
12 inline void swap(LL &x,LL &y){LL tmp=x;x=y;y=tmp;}
13 inline int remin(int a,int b){if (a<b) return a;return b;}
14 inline int remax(int a,int b){if (a>b) return a;return b;}
15 inline LL remin(LL a,LL b){if (a<b) return a;return b;}
16 inline LL remax(LL a,LL b){if (a>b) return a;return b;}
17 inline void read(int &x){x=0;int f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}x=x*f;}
18 inline void read(LL &x){x=0;LL f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}x=x*f;}
25 const int Maxn=1000000;
26 int n;
27 int a,b;
28 int t[Maxn+10];
29 int main(){
31     for (;n--;){
33         t[a]++;
34         t[b+1]--;
35     }
36     int Ans=0;
37     for (int i=1;i<=Maxn;i++){
38         t[i]=t[i-1]+t[i];
39         Ans=remax(Ans,t[i]);
40     }
41     printf("%d\n",Ans);
42     return 0;
43 }
View Code

posted @ 2014-10-31 17:25  WNJXYK  阅读(110)  评论(0编辑  收藏  举报