bzoj1178 [Apio2009]CONVENTION会议中心 区间dp+贪心
[Apio2009]CONVENTION会议中心
Time Limit: 15 Sec Memory Limit: 162 MB
Submit: 1130 Solved: 444
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
4 9
9 11
13 19
10 17
Sample Output
1 3
HINT
修复数据bug,并新加数据一组By NanoApe 2016.5.11
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<set> #define inf 1000000007
#define N 200007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch)){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
} int n,m;
int X[N],Y[N],next[N][],L[N],R[N];
struct data
{
int l,r;
friend bool operator < (const data &x,const data &y)
{
return x.r==y.r ? x.l>y.l : x.r<y.r;
}
}a[N],t[N]; int cal(int l,int r) {
int x=lower_bound(X+,X++m,l)-X;
if (Y[x]>r || x>m) return ;
int res=;
for (int i=;i>=;i--) if (next[x][i] && Y[next[x][i]]<=r) res+=<<i,x=next[x][i];
return res;
}
int main()
{
n=read();
for (int i=;i<=n;i++)
t[i].l=read(),t[i].r=read(),a[i]=t[i];
sort(t+,t++n); m=;
for (int i=;i<=n;i++)
if (m==||t[i].l>t[m].l) t[++m]=t[i];
for (int i=;i<=m;i++)
X[i]=t[i].l,Y[i]=t[i].r;
for (int i=,j=;i<=m;i++)
{
while (j<=m&&t[j].l<=t[i].r) j++;
if (j<=m) next[i][]=j;
}
for (int j=;j<=;j++)
for (int i=;i<=m;i++)
next[i][j]=next[next[i][j-]][j-];
int ans;
printf("%d\n",ans=cal(-inf,inf));
set<data> s;
s.insert((data){inf,inf});
s.insert((data){-inf,-inf});
int cnt=;
for (int i=;i<=n;i++)
{
set<data>::iterator x=s.lower_bound(a[i]),y=x;y--;
int l1=y->r,r1=a[i].l,l2=a[i].r,r2=x->l;
if (l1>=r1||l2>=r2) continue;
if (cal(l1+,r2-)==cal(l1+,r1-)+cal(l2+,r2-)+)
{
if (++cnt==ans) printf("%d",i);
else printf("%d ",i);
s.insert(a[i]);
}
}
}
bzoj1178 [Apio2009]CONVENTION会议中心 区间dp+贪心的更多相关文章
- BZOJ1178 [Apio2009]CONVENTION会议中心
本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权! Description Siruseri政府建造了 ...
- BZOJ1178 [Apio2009]CONVENTION会议中心 贪心 set
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1178 题意概括 一堆线段,现在取出最多条数,使其互不覆盖,并输出字典序最小的方案. 题解 这题好坑 ...
- 1178: [Apio2009]CONVENTION会议中心
1178: [Apio2009]CONVENTION会议中心 https://lydsy.com/JudgeOnline/problem.php?id=1178 分析: set+倍增. 首先把所有有包 ...
- 【BZOJ-1178】CONVENTION会议中心 倍增 + set (神思路好题!)
1178: [Apio2009]CONVENTION会议中心 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 812 Solved: 323[Subm ...
- 【bzoj1178】 Apio2009—CONVENTION会议中心
http://www.lydsy.com/JudgeOnline/problem.php?id=1178 (题目链接) 题意 给出n个区间,问在区间两两不相交的情况下最多能选出多少区间,并输出字典序最 ...
- bzoj 1178: [Apio2009]CONVENTION会议中心(少见做法掉落!)【贪心+二分】
数组若干+手动二分一个的算法,bzoj rank8 ===============================废话分割线=================================== 我我 ...
- bzoj 1178 [Apio2009]CONVENTION会议中心
这题好难啊! 我好菜啊! 思路:对于最多线段不相交, 我们可以按左端点sort之后,贪心取. 但是这个题要求选取的线段排序之后序号的字典序最小. 那么我们如果按序号贪心地从大往小往里放, 那么对于第k ...
- 【BZOJ】【1178】【APIO2009】convention会议中心
贪心 如果不考虑字典序的话,直接按右端点排序,能选就选,就可以算出ans…… 但是要算一个字典序最小的解就比较蛋疼了= = Orz了zyf的题解 就是按字典序从小到大依次枚举,在不改变答案的情况下,能 ...
- 【BZOJ 1178】【APIO 2009】CONVENTION会议中心
http://www.lydsy.com/JudgeOnline/problem.php?id=1178 这道题想了好久没想明白,倍增数组通过看题解很快就明白了,但是一小段区间内应有的最多线段数一直不 ...
随机推荐
- [SHELL]退出脚本
一,退出状态码 1,范围:0~255 2,查看退出状态码:必须在命令执行之后立即执行 ,显示的是脚本最后一条命令的退出状态码 echo $? 若f返回值为0,则表示正常 有异常为正值 二,exit 脚 ...
- https的主体过程
https其实就是基于SSL的http.加密后的http信息按理是不会被篡改和查看的. https的过程总体上是按照下面来进行的: 1.客户端发起请求,服务端返回一个SSL证书,证书里面有一公钥A. ...
- Python3 小工具-TCP发现
from scapy.all import * import optparse import threading import os def scan(ip): pkt=IP(dst=ip)/TCP( ...
- Netcore logging config
- Eclipse 安装SVN、Maven插件
1先安装subeclipse插件就是svn svn - http://subclipse.tigris.org/update_1.6.x 我这里是灰色的说明我安装过了这里只是截图说明下,我就不继续安装 ...
- 2.azkaban3.0安装
安装规划安装azkban1.安装配置数据库2.下载安装web server3.安装mulit executor4.安装azkaban插件AZKABAN参数安装出现的问题 安装规划 IP 角色 端口 1 ...
- springboot 整合apache shiro
这几天因为项目需要,学习了下shiro,由此留下一些记录,也希望对初学shiro的朋友有帮助. springboot 是这两年新兴起来的一个项目,它的出现是为了减少springmvc开发过程中需要引入 ...
- Spring Security 快速了解
在Spring Security之前 我曾经使用 Interceptor 实现了一个简单网站Demo的登录拦截和Session处理工作,虽然能够实现相应的功能,但是无疑Spring Security提 ...
- css滤镜让图片模糊
.mhblur { filter: url(blur.svg#blur); /* FireFox, Chrome, Opera */ -webkit-filter: blur(53px); /* Ch ...
- mysql+navicat安装小结
1,mysql到官方下载,navicat下载破解版 2,修改my.ini, 注意,需要手动创建data文件夹, 其中C:\MySql\mysql-5.7.17-winx64是解压mysql的目录 [m ...
