Stall Reservations POJ - 3190(贪心)
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
Many answers are correct for each test dataset; a program will grade your answer.
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 10
Stall 1 c1>>>>>>>>>>>>>>>>>>>>>>>>>>>
Stall 2 .. c2>>>>>> c4>>>>>>>>> .. ..
Stall 3 .. .. c3>>>>>>>>> .. .. .. ..
Stall 4 .. .. .. c5>>>>>>>>> .. .. ..
Other outputs using the same number of stalls are possible.
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std; const int maxn = 5e4+;
int n;
struct Node
{
int id;
int l,r;
}; int mp[maxn];
Node cow[maxn];
bool cmp1(Node a,Node b)
{
return a.l < b.l;
} bool operator<(Node a,Node b)
{
return a.r > b.r;
} priority_queue<Node>que;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d%d",&cow[i].l,&cow[i].r);
cow[i].id = i;
}
sort(cow+,cow++n,cmp1);
int k = ;
for(int i=; i<=n; i++)
{
if(que.empty())
{
mp[cow[i].id] = k;
}
else if(que.top().r < cow[i].l)
{ mp[cow[i].id] = mp[que.top().id];
que.pop();
}
else
mp[cow[i].id] = ++k;
que.push(cow[i]);
}
printf("%d\n",k);
for(int i=; i<=n; i++)
{
printf("%d\n",mp[i]);
}
}
Stall Reservations POJ - 3190(贪心)的更多相关文章
- Stall Reservations(POJ 3190 贪心+优先队列)
Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4434 Accepted: 158 ...
- Stall Reservations POJ - 3190 (贪心+优先队列)
Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11002 Accepted: 38 ...
- Greedy:Stall Reservations(POJ 3190)
牛挤奶 题目大意:一群牛很挑剔,他们仅在一个时间段内挤奶,而且只能在一个棚里面挤,不能与其他牛共享地方,现在给你一群牛,问你如果要全部牛都挤奶,至少需要多少牛棚? 这一题如果把时间区间去掉,那就变成装 ...
- poj 3190 贪心+优先队列优化
Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4274 Accepted: 153 ...
- POJ 3190 Stall Reservations贪心
POJ 3190 Stall Reservations贪心 Description Oh those picky N (1 <= N <= 50,000) cows! They are s ...
- POJ - 3190 Stall Reservations 贪心+自定义优先级的优先队列(求含不重叠子序列的多个序列最小值问题)
Stall Reservations Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one w ...
- 【POJ - 3190 】Stall Reservations(贪心+优先队列)
Stall Reservations 原文是English,这里直接上中文吧 Descriptions: 这里有N只 (1 <= N <= 50,000) 挑剔的奶牛! 他们如此挑剔以致于 ...
- POJ 3190 Stall Reservations【贪心】
POJ 3190 题意: 一些奶牛要在指定的时间内挤牛奶,而一个机器只能同时对一个奶牛工作.给你每头奶牛的指定时间的区间(闭区间),问你最小需要多少机器.思路:先按奶牛要求的时间起始点进行从小到大排序 ...
- poj 3190 Stall Reservations
http://poj.org/problem?id=3190 Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Su ...
随机推荐
- login_code
#! -*- coding:utf-8 -*-"""http://www.cnblogs.com/weke/articles/6271206.html前置和后置1.set ...
- iOS UIDatePicker设置为中文的方法
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 20, 200, 30)]; datePick ...
- Confluence 6 用户目录图例 - 使用 LDAP 授权,在用户第一次登陆时拷贝用户
上面的图:Confluence 连接到一个 LDAP 目录只用作授权,当用户登录 Confluence 的时候,使用 LDAP 授权并且将用户信息同步到本地路服务器上. https://www.cwi ...
- selenium关于断言的使用
基本介绍: Selenium工具专门为WEB应用程序编写的一个验收测试工具. Selenium的核心:browser bot,是用JAVASCRIPT编写的. Selenium工具有4种:Seleni ...
- Appium 常用方法总结 (python 版)
1.app后台运行 driver.background_app(5) 2.锁屏 driver.lock(5) 3.隐藏键盘 driver.hide_keyboard() 4.启动一个app或者在当前a ...
- 金蝶开k3wise客户端访问中间层不时提示远程服务器不存在或不可用
此问题一般是发生在WIN7客户端+中间层为WIN2008 R2系统,一般是中间层启用guest引起: a. 从Windows Vista以后, Negotiate (http://msdn.micro ...
- 如何保证Redis的高并发
单机的redis几乎不太可能说QPS超过10万+,一般在几万. 除非一些特殊情况,比如你的机器性能特别好,配置特别高,物理机,维护做的特别好,而且你的整体的操作不是太复杂. Redis通过主从架构,实 ...
- 一脸懵逼搭建Zookeeper分布式集群
1:首先将http://zookeeper.apache.org/ 下载好的zookeeper-3.4.5.tar.gz上传到三台虚拟机上,之前博客搭建好的(安装Zookeeper之前记得安装好你的j ...
- 一脸懵逼学习Hadoop中的序列化机制——流量求和统计MapReduce的程序开发案例——流量求和统计排序
一:序列化概念 序列化(Serialization)是指把结构化对象转化为字节流.反序列化(Deserialization)是序列化的逆过程.即把字节流转回结构化对象.Java序列化(java.io. ...
- linux服务器性能——CPU、内存、流量、磁盘使用率的监控
https://blog.csdn.net/u012859748/article/details/72731080