bzoj1651 / P2859 [USACO06FEB]摊位预订Stall Reservations
P2859 [USACO06FEB]摊位预订Stall Reservations
维护一个按右端点从小到大的优先队列
蓝后把数据按左端点从小到大排序,顺序枚举。
每次把比右端点比枚举线段左端点小的数据从优先队列中删掉。
在整个过程中队列的最大长度即为答案。
总之用优先队列模拟一下就ok了
对于luogu需要输出方案数的问题:
再开一个优先队列存未用的编号
每次有线段进队时取走最小的编号,出队时再还回来。
似乎暴力也行(大雾)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int max(int a,int b){return a>b?a:b;}
#define N 50005
struct data{
int l,r,id;
void init(int x){scanf("%d%d",&l,&r);id=x;}
bool operator < (const data &tmp) const{
return r>tmp.r;
}
}a[N]; priority_queue <data> h;
priority_queue <int,vector<int>,greater<int> > d;
bool cmp(const data &A,const data &B){return A.l<B.l;}
int n,mp[N],ans;
int main(){
scanf("%d",&n);
for(int i=;i<=n;++i) a[i].init(i),d.push(i);
sort(a+,a+n+,cmp);
for(int i=;i<=n;++i){
if(!h.empty()){
for(data q=h.top();!h.empty();q=h.top()){
if(q.r>=a[i].l) break;
d.push(mp[q.id]);h.pop();
}
}h.push(a[i]);
mp[a[i].id]=d.top(); d.pop();
ans=max(ans,h.size());
}printf("%d\n",ans);
for(int i=;i<=n;++i) printf("%d\n",mp[i]);
return ;
}
bzoj1651 / P2859 [USACO06FEB]摊位预订Stall Reservations的更多相关文章
- 洛谷P2859 [USACO06FEB]摊位预订Stall Reservations
P2859 [USACO06FEB]摊位预订Stall Reservations 题目描述 Oh those picky N (1 <= N <= 50,000) cows! They a ...
- [USACO06FEB]摊位预订Stall Reservations(贪心)
[USACO06FEB]摊位预订Stall Reservations 题目描述 Oh those picky N (1 <= N <= 50,000) cows! They are so ...
- 题解 P2859 【[USACO06FEB]摊位预订Stall Reservations】
题目链接: https://www.luogu.org/problemnew/show/P2859 思路: 首先大家会想到这是典型的贪心,类似区间覆盖问题的思路,我们要将每段时间的左端点从小到大排序, ...
- [USACO06FEB] Stall Reservations 贪心
[USACO06FEB] Stall Reservations 贪心 \(n\)头牛,每头牛占用时间区间\([l_i,r_i]\),一个牛棚每个时间点只能被一头牛占用,问最少新建多少个牛棚,并且每头牛 ...
- BZOJ1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 509 Sol ...
- poj 3190 Stall Reservations
http://poj.org/problem?id=3190 Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Su ...
- Stall Reservations(POJ 3190 贪心+优先队列)
Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4434 Accepted: 158 ...
- BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚( 线段树 )
线段树.. -------------------------------------------------------------------------------------- #includ ...
- BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
题目 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 553 ...
随机推荐
- 存储opline的内存地址可以实时跟踪opcode的执行
static intphp_handler(request_rec *r) { /* Initiliaze the context */ php_struct * volatile ctx; void ...
- parameter/argument
根据网上一些资料,对parameter和argument的区别,做如下的简单说明.1. parameter是指函数定义中参数,而argument指的是函数调用时的实际参数.2. 简略描述为:param ...
- Freemarker 基本数据类型
一 数据类型简介 freemarker 模板中的数据类型由如下几种: 1. 布尔型:等价于java中的boolean类型, 不同的是不能直接输出,可以转换成字符串再输出 2. 日期型:等价于java中 ...
- ubuntu 12.10上安装tftpd-hpa
ubuntu 12.10上安装tftpd-hpa 1)安装tftp-hpa,tftpd-hpa sudo apt-get install tftp-hpa tftpd-hpa tftp-hpa是cli ...
- 转:Java中字符串split() 的使用方法.
原文地址:https://blog.csdn.net/qq_27093465/article/details/54910323 挺有意思的一个问题 先看下面的方法,事先预测一下,经过split方法,按 ...
- CF750F New Year and Finding Roots 构造+树论
正解:构造 解题报告: 传送门! 交互题交互题!哇好新鲜啊QwQ 首先考虑最傻逼的做法,应该是每个人都能想到的 首先看一下它给的条件,考虑到完全二叉树的性质,就可以发现,如果给的邻居只有一个,说明是叶 ...
- python 基础 内置函数
内置参数 print(all([5,-1,5])) # 非0都是真 true print(all([0,-1,5])) # false print(any([1,0,5])) # 有一个数据为真,就为 ...
- eclipse整合spring+springMVC+Mybatis
一.新建Maven项目 点击菜单栏File项,选择New->Project,选中Maven Project,如下图: 二.配置pom.xml <?xml version="1.0 ...
- CSS 基础知识
CSS 实例(CSS声明总是以分号(;)结束,声明组以大括号({})括起来:) CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明: 选择器通常是您需要改变样式的 HTML 元素. 每条声明 ...
- Python中的__init__.py的作用
当用 import 导入该目录时,会执行 __init__.py 里面的代码 因此在__init__.py文件中,把深层的包的路径缩短,别的地方就可以在引用到目录级别时引到深层的包.