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 ...
随机推荐
- ORACLE环境变量定义
export在linux的bash中可以理解为设置环境变量.设置后能够被当前的shell及子shell使用. 这些变量的含义有一些有意义,可以查看相应的文档,我给你解释一些我知道的: ORACLE_H ...
- Java的输入语句以及本周对于文件读写的研究
日期:2018.9.20 博客期:010 星期四 ##:今天下午要考试 java(小考)!那么,我就应对相应的方法给出策略吧! 首先是 Java 里的输入语句,我一般是用Scanner类,用这个之前要 ...
- 基于多进程的Tcp套接字服务器
服务端 import socketfrom multiprocessing import Process def task(c): print('顾客吃点啥') while True: data = ...
- laravel 多对多关联 attach detach sync
用户表和角色表,多对多关联,一个用户有多个角色,一个角色属于多个用户 添加多对多关联 attach: 给1号用户添加1号角色,并把关联表的column字段赋值为$value,后边的数组需要的时候再添加 ...
- poj3662 二分+最短路
/* 给定一张无向图,要求找到1-n的路径,该路径上第k+1大的边是所有路径上最小的 如果没有1-n的路,那么输出-1 二分答案mid,遍历一次所有边,如果边权小于mid,则设为0,大于mid,则设为 ...
- tarjan求lca :并查集+dfs
//参考博客 https://www.cnblogs.com/jsawz/p/6723221.html#include<bits/stdc++.h> using namespace std ...
- linux添加自定义命令
想添加一个命令, 比如我输入 cdms 按回车, 然后就执行了: cd /mnt/gopath/src/test/app/ 这条命令方法: vi /etc/bashrc 在文件末尾添加 alias c ...
- 提取Word里的文本内容 C#
using DocumentFormat.OpenXml.Packaging; public static string TextFromWord(string path) { const strin ...
- 从零开始学C#——不再更新,直接进入高阶教程
从零开始学习C#不再更新,直接进入高阶教程. 入门教程,请自行谷歌.百度吧,有很多这样的教程. 编程是一件实践性很强的事情,那么接下来的文章将开始进行开发项目. 还在编程中迷茫的人们,先暂时放下一切的 ...
- cqoi2018
题解: 很多模板题 第一次写莫队还比较顺利 除了把排序的cmp写错..(还第一次遇到) 这题分块也可以 先预处理出g[i][j]代表前i个块,颜色为j的有多少种 f[i][j]表示i-j的块能构成多少 ...