题意:

  一个公告板上面贴海报,宽度都是一样的,长度可能不一样。后面的海报可能把前面的覆盖掉。问最后能看见多少张不同的海报。

思路:

  这题原来做过,是用线段树的区间染色写的。记录每个区间是纯色还是杂色。最后统计所有颜色。

  今天发现可以用一种类似扫描线的想法来做。想象一条扫描线从左往右走。用set来维护当前位置对应的海报集合。然后记录当前位置最新(能被看到)的海报是哪一张。

  最后统计一下能被看见的海报数量。

代码:

  

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <time.h> using namespace std; const int INF = <<;
const int MAXN = (int) 1e4+; struct event {
int x, t; //位置,时间
int status; //进还是出 void init(int xx, int tt, int ss) {
x = xx;
t = tt;
status = ss;
} bool operator < (const event &_) const {
if (x!=_.x) return x<_.x;
//同一位置时,入边在出边前面
//同是入边时,时间大的在前面
//同是出边时,时间小的在前面
return status*t > _.status*_.t;
}
}a[MAXN<<]; set<int> S;
bool vis[MAXN];
int n; void solve() {
S.clear();
memset(vis, false, sizeof(vis));
int l, r; scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%d%d", &l, &r);
a[i<<].init(l, i+, );
a[i<<|].init(r+, i+, -);
}
sort(a, a+n*); int ans = ;
set<int>::iterator p; for (int i = ; i < n*; i++) {
if (a[i].status>) S.insert(a[i].t);
else S.erase(a[i].t);
if (!S.empty()) {
p = S.end(); p--;
if (!vis[*p]) {
ans++;
vis[*p] = true;
}
}
}
printf("%d\n", ans);
} int main() {
#ifdef Phantom01
freopen("PKU2528.txt", "r", stdin);
#endif //Phantom01 int T;
scanf("%d", &T);
while (T--) {
solve();
} return ;
}

PKU 2528 Mayor's posters的更多相关文章

  1. poj 2528 Mayor's posters(线段树+离散化)

    /* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...

  2. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  3. POJ - 2528 Mayor's posters(dfs+分治)

    POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include< ...

  4. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  5. POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】

    任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  6. POJ 2528 Mayor's posters

    Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  7. POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59239   Accepted: 17157 ...

  8. poj 2528 Mayor's posters 线段树区间更新

    Mayor's posters Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...

  9. POJ 2528——Mayor's posters——————【线段树区间替换、找存在的不同区间】

    Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

随机推荐

  1. 【转载】Xmemcached用户指南

    一.XMemcached简介 XMemcached是一个新java memcachedclient.也许你还不知道memcached是什么?可以先看看这里.简单来说,Memcached 是一个高性能的 ...

  2. HDU 2120 Ice_cream's world I【并查集】

    解题思路:给出n对点的关系,求构成多少个环,如果对于点x和点y,它们本身就有一堵墙,即为它们本身就相连,如果find(x)=find(y),说明它们的根节点相同,它们之间肯定有直接或间接的相连,即形成 ...

  3. 如何使easyui的datagrid 高度自适应

    如何使easyui的datagrid 高度自适应? 最开始使用easyui的datagrid加载数据时,对其设置的高度都是固定值,数据较多时table表现为滚动条形式.某天,老大突然需要datagri ...

  4. [LOJ2422]【NOIP2015】斗地主

    大名鼎鼎的NOIP2015D1T3 题意: 由于一些众所周知的原因,没有完整题面…… 给你一副斗地主的手牌(牌数<=23),问最少要几次能出完: 包含双王,没有癞子,连对要三连对以上,可以直接出 ...

  5. HYSBZ-1040 骑士 基环树上的树状dp

    题目链接:https://cn.vjudge.net/problem/HYSBZ-1040 题意 Z国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英. 他们劫富济贫,惩恶扬善,受到社会各界的 ...

  6. Vue组件通信之Bus

    关于组件通信我相信小伙伴们肯定也都很熟悉,就不多说了,对组件通信还不熟悉的小伙伴移步这里. 在vue2.0中 $dispatch 和 $broadcast 已经被弃用.官方文档中给出的解释是: 因为基 ...

  7. 网页里如何使用js屏蔽鼠标右击事件

    图片.png 在后台管理系统里面,遇到了这样的一个问题,右击ztree菜单,弹出修改界面,但是,现在确实这样的,右击默认弹出功能提示的框框,看上去似乎很影响自己想要的功能,只能禁用了,那么,网页里如何 ...

  8. 不要在.h文件中定义变量

    今天在头文件.h中初始化了一个数组和函数,在编译的时候提示这个数组和函数重新定义了,检查后发现,犯了一个致命的错误,在头文件中定义变量... 以下引用别人的一篇说明,警示自己. C语言作为一种结构化的 ...

  9. #undef 的用法

    在Visual Studio2008中编写如下代码: #include <iostream> using namespace std; int main() { #define MODI ...

  10. 洛谷 P1332 血色先锋队

    P1332 血色先锋队 题目描述 巫妖王的天灾军团终于卷土重来,血色十字军组织了一支先锋军前往诺森德大陆对抗天灾军团,以及一切沾有亡灵气息的生物.孤立于联盟和部落的血色先锋军很快就遭到了天灾军团的重重 ...