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 ...
随机推荐
- Java_解惑
书名 ================================================================================================= ...
- Oracle 之 外部表
一.外部表概述 外部表只能在Oracle 9i 之后来使用.简单地说,外部表,是指不存在于数据库中的表. 通过向Oracle 提供描述外部表的元数据,我们可以把一个操作系统文件当成一个只读的数 据库表 ...
- Confluence 6 "Duplicate Key" 相关问题解决
如果你遇到了下面的错误信息,例如: could not insert: [bucket.user.propertyset.BucketPropertySetItem#bucket.user.prope ...
- Laravel 项目中使用 Bootstrap 框架
Laravel 如何引入 Bootstrap 如官方文档所言,Laravel 并不强制你使用 CSS 框架,但是开箱提供了对 Bootstrap 的支持,在 resources/js/bootstra ...
- ES6 Promise 全面总结
转载:点击查看原文 ES6 Promise对象 ES6中,新增了Promise对象,它主要用于处理异步回调代码,让代码不至于陷入回调嵌套的死路中. @-v-@ 1. Promise本质 Promise ...
- C++ GetComputerName()
关于函数“GetComputerName()”,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724295(v=vs.85 ...
- SSM文件下载
SSM框架文件下载比文件上传稍微麻烦一点,但这次还是写成最简朴的形式,哈哈~如下 参考:http://blog.csdn.net/lcx556224523/article/details/702076 ...
- python接收邮件
# -*- coding: utf-8 -*- import poplib import email from email.parser import Parser from email.header ...
- linux的systemctl服务及其使用
一.systemd 系统初始化程序,系统开始的第一个进程,PID为1 二.systemctl命令 systemctl list-units ##列出当前系统服务的状态 systemctl lis ...
- 51 Nod 1256 乘法逆元(数论:拓展欧几里得)
1256 乘法逆元 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出2个数M和N(M < N),且M与N互质,找出一个数K满足0 < K ...