1178: [Apio2009]CONVENTION会议中心
1178: [Apio2009]CONVENTION会议中心
https://lydsy.com/JudgeOnline/problem.php?id=1178
分析:
set+倍增。
首先把所有有包含的去掉,只保留包含的最小的边(如果两条线段中的一条包含另一条,那么保留被包含的)然后此时就可以直接贪心了。直接从一条边找不想交的下一条边。然后就行了(因为此时没有包含的,左端点递增,右端点递增)。
因为每条边的下一条是唯一的,那么可以倍增维护往后走2^i步,到的点。此时可以快速知道任意一段区间的最多可以有多少条边了。
因为要字典序最小,从编号小的可以是枚举,如果这条边[l,r]可以加进去。tl,tr如下图所示。

那么[l,r]可以加入的条件是,calc(tl+1,tr-1)=calc(tl+1,l-1)+calc(r+1,tr-1)+1,calc(l,r)表示l~r最多可以放几条线段。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
const int INF = 1e9;
const int Log = ; struct Edge{
int l, r;
Edge() { }
Edge(int a,int b) { l = a, r = b; }
bool operator < (const Edge &A) const {
return r == A.r ? l > A.l : r < A.r;
}
}A[N], ori[N];
int disc[N << ], f[N][Log + ], X[N], Y[N], m = ;
set<Edge>s; int Calc(int l,int r) {
int p = lower_bound(X + , X + m + , l) - X, ans = ; // ans=1!!!
if (Y[p] > r || p > m) return ;
for (int i = Log; i >= ; --i)
if (f[p][i] && Y[f[p][i]] <= r)
ans += ( << i), p = f[p][i];
return ans;
} int main() {
int n = read();
for (int i = ; i <= n; ++i) {
A[i].l = read(), A[i].r = read();
disc[i] = A[i].l, disc[i + n] = A[i].r;
}
sort(disc + , disc + n + n + );
int cnt = ;
for (int i = ; i <= n + n; ++i) if (disc[i] != disc[cnt]) disc[++cnt] = disc[i];
for (int i = ; i <= n; ++i) {
A[i].l = lower_bound(disc + , disc + cnt + , A[i].l) - disc;
A[i].r = lower_bound(disc + , disc + cnt + , A[i].r) - disc;
ori[i] = A[i];
}
sort(A + , A + n + );
X[m] = A[m].l, Y[m] = A[m].r;
for (int i = ; i <= n; ++i)
if (A[i].l > A[m].l) A[++m] = A[i], X[m] = A[m].l, Y[m] = A[m].r;
for (int i = , j = ; i <= m; ++i) {
while (j <= m && A[j].l <= A[i].r) j ++;
if (j <= m) f[i][] = j;
}
for (int j = ; j <= Log; ++j)
for (int i = ; i <= m; ++i) f[i][j] = f[f[i][j - ]][j - ]; int ans = Calc(-INF, INF);
cout << ans << "\n"; s.insert(Edge(INF, INF));
s.insert(Edge(-INF, -INF)); int now = ;
for (int i = ; i <= n; ++i) {
set<Edge> :: iterator x = s.lower_bound(ori[i]), y = x; y --; // 端点没有重复的,可以直接set的lower_bound
int tl = y->r, tr = x->l, l = ori[i].l, r = ori[i].r;
if (tl >= l || tr <= r) continue;
if (Calc(tl + , tr - ) == Calc(tl + , l - ) + Calc(r + , tr - ) + ) {
if (++now == ans) return printf("%d",i), ;
else printf("%d ",i);
s.insert(ori[i]);
}
}
return ;
}
1178: [Apio2009]CONVENTION会议中心的更多相关文章
- bzoj 1178 [Apio2009]CONVENTION会议中心
这题好难啊! 我好菜啊! 思路:对于最多线段不相交, 我们可以按左端点sort之后,贪心取. 但是这个题要求选取的线段排序之后序号的字典序最小. 那么我们如果按序号贪心地从大往小往里放, 那么对于第k ...
- bzoj 1178: [Apio2009]CONVENTION会议中心(少见做法掉落!)【贪心+二分】
数组若干+手动二分一个的算法,bzoj rank8 ===============================废话分割线=================================== 我我 ...
- bzoj1178 [Apio2009]CONVENTION会议中心 区间dp+贪心
[Apio2009]CONVENTION会议中心 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1130 Solved: 444[Submit][S ...
- BZOJ1178 [Apio2009]CONVENTION会议中心
本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权! Description Siruseri政府建造了 ...
- 【bzoj1178】 Apio2009—CONVENTION会议中心
http://www.lydsy.com/JudgeOnline/problem.php?id=1178 (题目链接) 题意 给出n个区间,问在区间两两不相交的情况下最多能选出多少区间,并输出字典序最 ...
- BZOJ1178 [Apio2009]CONVENTION会议中心 贪心 set
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1178 题意概括 一堆线段,现在取出最多条数,使其互不覆盖,并输出字典序最小的方案. 题解 这题好坑 ...
- 【BZOJ】【1178】【APIO2009】convention会议中心
贪心 如果不考虑字典序的话,直接按右端点排序,能选就选,就可以算出ans…… 但是要算一个字典序最小的解就比较蛋疼了= = Orz了zyf的题解 就是按字典序从小到大依次枚举,在不改变答案的情况下,能 ...
- 【BZOJ-1178】CONVENTION会议中心 倍增 + set (神思路好题!)
1178: [Apio2009]CONVENTION会议中心 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 812 Solved: 323[Subm ...
- 【BZOJ 1178】【APIO 2009】CONVENTION会议中心
http://www.lydsy.com/JudgeOnline/problem.php?id=1178 这道题想了好久没想明白,倍增数组通过看题解很快就明白了,但是一小段区间内应有的最多线段数一直不 ...
随机推荐
- Debian下Cannot set LC_CTYPE to default locale: No such file or directory解决方法
把语言环境变量改为英文 将Ubuntu系统语言环境改为英文的en_US.UTF-8 查看当前系统语言环境 locale 编辑配置文件,将zh_US.UTF-8改为en_US.UTF-8,zh改为en ...
- Yii2.0 发送邮件时中文附件乱码的问题
yii自带的邮件类使用的是MIME 协议,发送附件时用的是MIME 协议的 Content-disposition扩展,用扩展下载中文名称的附件时有时会正常,有时会乱码. 只需找到如下文件 的如下方法 ...
- cocos2d-x中关于打包成APK的问题
转载自:http://blog.csdn.net/u013315178/article/details/51254630 之前在网上看了很多的帖子大多数用ide 来打包 太麻烦了 而且一般没有人现场指 ...
- C、CSL 的密码 【set暴力 || 后缀数组】 (“新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛 )
题目传送门:https://ac.nowcoder.com/acm/contest/551/C 题目描述 众所周知,CSL 最喜欢的密码是 ******.于是有一天…… 为了改变这一点,他决定 ...
- ethereumjs/ethereumjs-vm-2-API文档
https://github.com/ethereumjs/ethereumjs-vm/blob/master/docs/index.md vm.runBlockchain Processes blo ...
- Redis简单集群配置
参考链接为:http://blog.csdn.net/u014230881/article/details/71123494 比较系统学习和熟练使用Redis命令可参考该教程:http://www.r ...
- C++练习 | 运算符重载练习(字符串相关)
#include <iostream> #include <cmath> #include <cstring> #include <string> #i ...
- Docker 学习记录(基础命令)
1. 获取镜像 docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签] ===> docker pull ubuntu:16:04 2.运 ...
- 二进制mysql安装相关知识
建议安装5.x版本 高版本没安装经验的慎用 1.1 关闭防火墙systemctl stop firewalld.service #停止firewall#慎用 systemctl disable fir ...
- 【Linux】文件、目录权限及归属
访问权限: 可读(read):允许查看文件内容.显示目录列表 可写(write):允许修改文件内容,允许在目录中新建.移动.删除文件或子目录 可执行(execute):允许运行程序.切换目录 归属: ...