博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3190 Stall Reservations (贪心+优先队列)
阅读量:4519 次
发布时间:2019-06-08

本文共 2028 字,大约阅读时间需要 6 分钟。

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 periodAn assignment of cows to these stalls over timeMany 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.

 

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 10 Stall 1 c1>>>>>>>>>>>>>>>>>>>>>>>>>>> Stall 2 .. c2>>>>>> c4>>>>>>>>> .. .. Stall 3 .. .. c3>>>>>>>>> .. .. .. .. Stall 4 .. .. .. c5>>>>>>>>> .. .. ..
Other outputs using the same number of stalls are possible.

Source

 
一些奶牛要在指定的时间内挤牛奶,而一个机器只能同时对一个奶牛工作。给你每头奶牛的指定时间的区间,问你最小需要多少机器。
 
先按起始时间从小到大排序,起始时间相同则按结束时间从小到大排序
 
然后用一个优先队列来维护,vis记录奶牛的工作机器
 
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 using namespace std; 9 #define N 6000010 int n;11 int vis[N];12 struct Node13 {14 int l,r;15 int pos;16 bool friend operator < (Node a,Node b)17 {18 if(a.r!=b.r)19 return a.r>b.r;20 }21 }p[N];22 bool cmp(Node a,Node b)23 {24 if(a.l!=b.l)25 return a.l
q;42 q.push(p[0]);43 vis[p[0].pos]=ans;44 45 for(int i=1;i
View Code

 

转载于:https://www.cnblogs.com/UniqueColor/p/4764549.html

你可能感兴趣的文章
红帽旗下Linux的版本说明RedHat、CentOS、Fedora、OEL等
查看>>
[转载]莫欺少年穷-----作者文笔真好
查看>>
jQuery快速入门知识重点
查看>>
写作(1~3)
查看>>
Hadoop数据类型
查看>>
LR中,URL -based script与HTML -based script区别
查看>>
清除IE中Ajax缓存,Chrome不需要
查看>>
日期时间格式化方法,可以格式化年、月、日、时、分、秒、周
查看>>
PairWork-电梯调度程序结对编程【附加题】
查看>>
Ext.Net学习笔记12:Ext.Net GridPanel Filter用法
查看>>
陪伴我走过春夏秋冬的校园
查看>>
bind()与connect()——计网中socket的使用
查看>>
ASP.NET WebApi 入门
查看>>
我想成为坐在路边鼓掌的人
查看>>
Html页面中Flash的播放,并利用JS变换Flash
查看>>
生成一条短信记录
查看>>
UNICODE,GBK,UTF-8区别
查看>>
HTML页面放大镜效果
查看>>
构建之法阅读笔记01
查看>>
【旧文章搬运】调试没有符号的驱动时如何断在入口点处
查看>>