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 这道题想了好久没想明白,倍增数组通过看题解很快就明白了,但是一小段区间内应有的最多线段数一直不 ...
随机推荐
- win7下本地运行spark以及spark.sql.warehouse.dir设置
SparkSession spark = SparkSession .builder() .master("local[*]") .enableHiveSupport() .con ...
- Python+Opencv实现把图片转为视频
1. 安装Opencv包 在Python命令行输入如下命令(如果你使用的Anaconda,直接进入Anaconda Prompt键入命令即可.如果你不知道Anaconda是什么,可以参考王树义老师的文 ...
- CryptoZombies学习笔记——Lesson5
chapter1:token代币 简而言之,通证就是支持交易的包含一系列规范的函数接口的一个智能合约,发币可以用ERC20标准,但是像僵尸这种非同质化代币,需要用ERC721标准 chapter2:e ...
- Centos6配置开启FTP Server
vsftpd作为FTP服务器,在Linux系统中是非常常用的.下面我们介绍如何在centos系统上安装vsftp. 什么是vsftpd vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序 ...
- POJ 1755 Triathlon(线性规划の半平面交)
Description Triathlon is an athletic contest consisting of three consecutive sections that should be ...
- Python中的global和nonlocal
在Python中,一个变量的scope范围从小到大分成4部分:Local Scope(也可以看成是当前函数形成的scope),Enclosing Scope(简单来说,就是外层函数形成的scope), ...
- mysql 相同表结构拷贝数据
第一种方法: 在导出表结构的时候可以勾选导出数据: 第二种方法: 表已经存在了,只需要数据即可.这个时候可以编写sql语句(暂不支持不同服务器之间的表数据复制) insert into tab_a(i ...
- (转)《linux性能及调优指南》 3.3 内存瓶颈
翻译:Hank (http://blog.csdn.net/fireroll)版权所有,尊重他人劳动成果,转载时请注明作者和原始出处及本声明.原文名称:<Linux Performance an ...
- xpath获取块元素下<br>下的信息
再爬虫取字段的时候遇到一种类似下面的结构: <p> <br> "通用名称:xxxxxx" </p> 用xpath取的方式://p//text() ...
- 第22天:js改变样式效果
一.输出语句 1.alert:弹出警示框(用的非常少,用户体验不好)完整写法:window.alert(“执行语句”):window对象,窗口,一般情况可省略alert(123); 2.console ...
