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 ...
随机推荐
- POJ--3321 Apple Tree(树状数组+dfs(序列))
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22613 Accepted: 6875 Descripti ...
- 要学习的UML图
这是人人都是产品经理里的一节内容,这是个简单的例子,我觉得重要就摘抄一下 UML是要好好学习的一门课程呀
- 自动解压vsftpd上传的文件
rsyslog.conf配置自定义模板 $template ssolog,"%msg%\n"if $programname == 'vsftpd' then ^/bin/auto_ ...
- grunt学习一
grunt是前端自动化工具之一.下面是是grunt的简单小示例: 在使用grunt,确保安装nodejs,如果不清楚,可以百度找相关教程,这个教程已经烂大街了. 1.打开cmd,以管理员的身份.(或者 ...
- 【Python】小练习
1.python爬虫 (1)抓取一个新闻网上含有某一关键字的新闻,http://internasional.kompas.com/就是这个网站上面所有内容含有THAAD这个关键词的新闻 (2)爬取大众 ...
- 了解Linux的进程与线程
了解Linux的进程与线程 http://timyang.net/linux/linux-process/ 上周碰到部署在真实服务器上某个应用CPU占用过高的问题,虽然经过tuning, 问题貌似已经 ...
- utf8 与 utf-8区别
在使用中常常遇到 utf-8 和 utf8,现在终于弄明白他们的使用不同之处了,现在来和大家分享一下,下面我们看一下 utf8 和 UTF-8 有什么区别. "UTF-8" 是标准 ...
- 通过反射,获取linkedHashMap的最后一个键值对。对map按照值进行排序。
1:通过反射,获取linkedHashMap的最后一个键值对. Map<Integer, Integer> map = new LinkedHashMap<>(); Field ...
- WebService之Axis2(1):用POJO实现0配置的WebService
Axis2是一套崭新的WebService引擎,该版本是对Axis1.x重新设计的产物.Axis2不仅支持SOAP1.1和SOAP1.2,还集成了非常流行的REST WebService,同时还支持S ...
- [LeetCode] 675. Cut Off Trees for Golf Event_Hard tag: BFS
You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-nega ...