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 这道题想了好久没想明白,倍增数组通过看题解很快就明白了,但是一小段区间内应有的最多线段数一直不 ...
随机推荐
- (持续更新) CSS属性持续记录
可以去除ul的li标签自带的圆点list-style-type: none; 可以将自己的光标改变样式:cursor: pointer;
- 1067. [SCOI2007]降雨量【线段树】
Description 我们常常会说这样的话:“X年是自Y年以来降雨量最多的”.它的含义是X年的降雨量不超过Y年,且对于任意 Y<Z<X,Z年的降雨量严格小于X年.例如2002,2003, ...
- PHP-----TP框架----命名空间
TP框架----命名空间 命名空间,起什么作用??? [1]命名空间是一个虚拟的目录,这个文件有可能存在这个电脑里的任何一个地方,但是如果要把这个文件它的命名空间全部写成同一个那么这些文件就相当于在同 ...
- [19/04/28-星期日] GOF23_结构型模式(享元模式)
一.享元模式(FlyWeight,轻量级) [共享类与非共享类] /*** *FlyweightFactory享元工厂类: 创建并管理享元对象,享元池一般设计成键值对 */ package cn.sx ...
- CSS中背景图片的background-position中的left top到底是相对于谁的?
在学习的时候遇到了如下问题: CSS中背景图片的background-position中的left top到底是相对于谁的,content-box?padding-box?border-box? ba ...
- PAT——1071. 小赌怡情
常言道“小赌怡情”.这是一个很简单的小游戏:首先由计算机给出第一个整数:然后玩家下注赌第二个整数将会比第一个数大还是小:玩家下注t个筹码后,计算机给出第二个数.若玩家猜对了,则系统奖励玩家t个筹码:否 ...
- DataFrame概念与创建
一 概念 Pandas是一个开源的Python数据分析库.Pandas把结构化数据分为了三类: Series,1维序列,可视作为没有column名的.只有一个column的DataFrame: Dat ...
- 【JavaScript-基础-文件上传】
Upload 最原始方式 form表单提交 // html <form method="get" action="/test/upload"> &l ...
- Git IDEA Move or commit them before merge
提交代码遇到这个问题. Move or commit them before merge 百度了一下都是在Gitbash 中敲命令. 在团队协作中 你总不能去敲命令吧 后来在组长的怂恿下,我删除了一个 ...
- 修改系统UITableViewCell的ImageView大小
代码如下: CGSize itemSize = CGSizeMake(, ); UIGraphicsBeginImageContext(itemSize); CGRect imageRect = CG ...