Bzoj1651: [usaco 2006 Feb] stall reservations dedicated Cowshed

Source: Internet
Author: User
1651: [usaco Feb] stall reservations dedicated cowshed time limit: 10 sec memory limit: 64 MB
Submit: 509 solved: 280
[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 .. 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 stallrequired in the barn so that each cow can have her private milking period * an assignment of cows to these stils over time

There are nheaded cows, and each ox has a time to drink water. During this time, it will be dedicated to a stall. Now it gives the time period for each ox to drink water and asks how many stall should be required to meet their requirements.

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 input5
1 10
2 4
3 6
5 8
4 7
Sample output4


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 stils are possible. Hint

 

Try this data. For sort by end point, then greedy's Practice 1 3 5 7 6 9 10 11 8 12 4 13 correct output should be 3

 

Source

Silver

Question: Max is the answer for the number of times that each time point is overwritten. The original differential sequence can be used in this way. Long knowledge. After the original sequence is divided, the prefix and the value representing the change point do not need to create a line segment tree. Code:
 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #include<string>12 #define inf 100000000013 #define maxn 100001014 #define maxm 500+10015 #define eps 1e-1016 #define ll long long17 #define pa pair<int,int>18 using namespace std;19 inline int read()20 {21     int x=0,f=1;char ch=getchar();22     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}23     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}24     return x*f;25 }26 int n,sum=0,ans=0,mx=0,a[maxn];27 int main()28 {29     freopen("input.txt","r",stdin);30     freopen("output.txt","w",stdout);31     n=read();32     for(int i=1;i<=n;i++)33     {34      int x=read(),y=read()+1;    35      a[x]++,a[y]--;36      if(y>mx)mx=y;37     }38     for(int i=1;i<=mx;i++)39      {40          sum+=a[i];41          if(sum>ans)ans=sum;42      }43     printf("%d\n",ans); 44     return 0;45 }
View code

 

Bzoj1651: [usaco 2006 Feb] stall reservations dedicated Cowshed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.