PKU 2528 Mayor's posters
题意:
一个公告板上面贴海报,宽度都是一样的,长度可能不一样。后面的海报可能把前面的覆盖掉。问最后能看见多少张不同的海报。
思路:
这题原来做过,是用线段树的区间染色写的。记录每个区间是纯色还是杂色。最后统计所有颜色。
今天发现可以用一种类似扫描线的想法来做。想象一条扫描线从左往右走。用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的更多相关文章
- poj 2528 Mayor's posters(线段树+离散化)
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- POJ - 2528 Mayor's posters(dfs+分治)
POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include< ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】
任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 2528 Mayor's posters
Mayor's posters Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59239 Accepted: 17157 ...
- poj 2528 Mayor's posters 线段树区间更新
Mayor's posters Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...
- POJ 2528——Mayor's posters——————【线段树区间替换、找存在的不同区间】
Mayor's posters Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
随机推荐
- Avalon.js 实现列表
<table border="0" cellpadding="0" cellspacing="0" class="tab1& ...
- oc消息转发机制本质
第一级转发:主体不变,动态添加对应函数: 第二级转发:函数不变,切换接收主体: 第三极转发:函数签名不变,主体和函数都有可能变化: 1.使用函数的动态添加技术: 2.使用的类似is-a swzzing ...
- 优动漫PAINT基础系列之图层模式
在绘画软件优动漫PAINT中,笔刷工具属性中的消除锯齿变成灰色无法选择了?铅笔绘制没有压感?快来改改图层模式~ 优动漫PAINT下载:http://www.dongmansoft.com/xiazai ...
- Linux下重启mysql数据库的方法
原文地址:Linux下重启mysql数据库的方法作者:于士博的视频教程 方法一: 命令: [root@localhost /]# /etc/init.d/mysql start|stop|rest ...
- 小程序QQ版表情解析组件
代码片段: [https://developers.weixin.qq.com/s/KLaD5MmD7V45) GitHub: https://github.com/WozHuang/Miniprog ...
- [NOIP2015普及组]推销员
题目:洛谷P2672.codevs5126.Vijos P1977 题目大意:有个推销员要去推销,要你求他推销1~n户人家分别最多花多少“疲劳值”.具体见题目. 解题思路:如果用$O(n^2)$做的话 ...
- hdfs的HA集群搭建的相关配置
前期准备就不详细说了 .修改Linux主机名 .修改IP .修改主机名和IP的映射关系 ######注意######如果你们公司是租用的服务器或是使用的云主机(如华为用主机.阿里云主机等) /etc/ ...
- PID的原理
来源:https://www.cnblogs.com/foxclever/p/8902029.html 在自动控制中,PID及其衍生出来的算法是应用最广的算法之一.各个做自动控制的厂家基本都有会实现这 ...
- cogs 181. [USACO Jan07] 最高的牛
181. [USACO Jan07] 最高的牛 ★★ 输入文件:tallest.in 输出文件:tallest.out 简单对比时间限制:1 s 内存限制:32 MB FJ's N ( ...
- deeplink技术的两篇资料
两篇资料如下: https://zhuanlan.zhihu.com/p/20694818?refer=ouyangchen http://www.sohu.com/a/122694049_49134 ...