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 ...
随机推荐
- 【紫书】Oil Deposits UVA - 572 dfs求联通块
题意:给你一个地图,求联通块的数量. 题解: for(所有还未标记的‘@’点) 边dfs边在vis数组标记id,直到不能继续dfs. 输出id及可: ac代码: #define _CRT_SECURE ...
- Oracle安装部署之Oracle 10g在redhat5下的安装
[root@localhost ~]# groupadd dba -g 111 [root@localhost ~]# groupadd oinstall -g 110 [root@localhost ...
- python面向对象高级:定制类
Python的class中还有许多这样有特殊用途的函数,可以帮助我们定制类. 比如: __str__ 与__repr____iter____getitem____call__ __str__ 与__r ...
- 【Python算法】遍历(Traversal)、深度优先(DFS)、广度优先(BFS)
图结构: 非常强大的结构化思维(或数学)模型.如果您能用图的处理方式来规范化某个问题,即使这个问题本身看上去并不像个图问题,也能使您离解决问题更进一步. 在众多图算法中,我们常会用到一种非常实用的思维 ...
- PL/SQL常用表达式及举例(一)
IF 判断条件 THEN 满足条件时执行语句 END IF; DECLARE v_countResult NUMBER; BEGIN SELECT COUNT(empno) INTO v_countR ...
- 64位windows 7下配置TortoiseGit(转)
原文:http://our2848884.blog.163.com/blog/static/146854834201152325233854/ 最近感觉自己电脑上的代码太乱了,东一块.西一块……于是决 ...
- 【Python】【Web.py】python调用html【问题:echart图标调用html上未显示】
code调用123.html和echarts.min.js文件 code.py import web import execjs urls = ( '/hello', 'hello', ) app = ...
- 【代码备份】ZJ10086测试环境成功代码备份
vuser_init(){ lr_start_transaction("login"); web_url("101.132.17.138", ...
- Django +uwsgi+python3+nginx + mysql 部署
环境: 服务器ip:192.168.0.110 centos服务器 6.4 + mysql 5.6 + django1.11 +nginx 1.13.7 + uwsgi 2.0.18 uwsgi介绍 ...
- SqlServer--bat批处理执行sql语句1-osql
首先需要知道,此处使用的批处理命令是osql ,如果安装了SqlServer,目录类似: D:\Program Files\Microsoft SQL Server\100\Tools\Binn 脚本 ...