POJ 3190 priority_queue 贪心
思路:
贪心?就算是吧
先把所有的开始时间排个序
如果当前的能匹配上已有的牛栏,就找开始时间最早的那个。
否则新加一个牛栏
整个过程用priority_queue实现就OK了。。
//By SiriusRen
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,t=1,s[55555];
struct Node {int pos,begin,end;}node[55555];
struct Sirius{int time,num;}jy;
priority_queue<Sirius>pq;
bool operator<(Sirius a,Sirius b){return a.time>b.time;}
bool cmp(Node a,Node b){return a.begin<b.begin;}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&node[i].begin,&node[i].end);
node[i].pos=i;
}
sort(node+1,node+1+n,cmp);
jy.num=1;jy.time=node[1].end;
pq.push(jy);
s[node[1].pos]=1;
for(int i=2;i<=n;i++){
if(node[i].begin>pq.top().time){
jy=pq.top();
pq.pop();
s[node[i].pos]=jy.num;
jy.time=node[i].end;
pq.push(jy);
}
else{
t++;
jy.time=node[i].end;
jy.num=t;
s[node[i].pos]=t;
pq.push(jy);
}
}
printf("%d\n",t);
for(int i=1;i<=n;i++)printf("%d\n",s[i]);
}
POJ 3190 priority_queue 贪心的更多相关文章
- Stall Reservations POJ - 3190 (贪心+优先队列)
Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11002 Accepted: 38 ...
- Stall Reservations POJ - 3190(贪心)
Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked ...
- 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【贪心】
POJ 3190 题意: 一些奶牛要在指定的时间内挤牛奶,而一个机器只能同时对一个奶牛工作.给你每头奶牛的指定时间的区间(闭区间),问你最小需要多少机器.思路:先按奶牛要求的时间起始点进行从小到大排序 ...
- POJ -3190 Stall Reservations (贪心+优先队列)
http://poj.org/problem?id=3190 有n头挑剔的奶牛,只会在一个精确时间挤奶,而一头奶牛需要占用一个畜栏,并且不会和其他奶牛分享,每头奶牛都会有一个开始时间和结束时间,问至少 ...
- poj 3190 Stall Reservations 贪心 + 优先队列
题意:给定N头奶牛,每头牛有固定的时间[a,b]让农夫去挤牛奶,农夫也只能在对应区间对指定奶牛进行挤奶, 求最少要多少个奶牛棚,使得在每个棚内的奶牛的挤奶时间不冲突. 思路:1.第一个想法就是贪心,对 ...
- 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) 挑剔的奶牛! 他们如此挑剔以致于 ...
- Stall Reservations(POJ 3190 贪心+优先队列)
Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4434 Accepted: 158 ...
随机推荐
- [CSS3] Image Width with sizes (srcset & sizes)
What if the image won't be displayed at the full viewport width? Then you need something more than s ...
- DataTables warning: table id=dataTable - Requested unknown parameter 'acceptId' for row 0. For more
重点内容 DataTables warning: table id=dataTable - Requested unknown parameter 'acceptId' for row 0. For ...
- we标签
功能: · 辅助标签.配合其它标签使用,防止与标准html标签冲突 · 别名为test 使用方法: <we [name=key]>[value]</we& ...
- Testbench代码设计技巧
Testbench代码设计技巧 " There are many ways " to code a test case, it all depens on the creativi ...
- jquery的clone()引发的问题,下拉框点击没有反应
此段代码是对某块元素的移位:上移.下移.对比修改前后的两段代码: 修改前: //点击移位 function move(obj,posi){ var al=$(obj).parent('li').par ...
- python 3.x 学习笔记8 (os模块及xml修改)
1.os模块操作 os.getcwd(): # 查看当前所在路径. os.listdir(path): ...
- C# AssemblyResolve事件可能不触发
C# AssemblyResolve事件需要引用的dll的“复制本地”属性设置为False,如果为True,可能不会触发这个事件的处理函数. 我想设计一个自动加载分架构的C++/CLI的dll,用到了 ...
- Apache Ignite - 轉
Ignite Docs Online: ignite-doc-cn https://dongwq.gitbooks.io/ignite-doc/content/index.html - Apache ...
- windows下安装mycat,并简单使用
使用mycat需要先安装jdk1.7以上 参考:http://www.cnblogs.com/llhhll/p/9257764.html 1从官网下载解压后目录如下(1.6版本) 下载地址:https ...
- 关于Spring的69个面试问答——终极列表 (转)
这篇文章总结了一些关于Spring框架的重要问题,这些问题都是你在面试或笔试过程中可能会被问到的.下次你再也不用担心你的面试了,Java Code Geeks这就帮你解答. 大多数你可能被问到的问题都 ...