(线段树)Mayor's posters --poj -- 2528
链接:
http://poj.org/problem?id=2528
覆盖问题, 要从后往前找, 如果已经被覆盖就不能再覆盖了,否则就可以覆盖
递归呀递归什么时候我才能吃透你
代码:
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
using namespace std; #define Lson r<<1
#define Rson r<<1|1 const int N = *1e4+; struct Node
{
int L, R;
}s[N<<]; struct node
{
int L, R;
bool isCover;
int Mid()
{
return (L+R)>>;
}
}a[N<<]; int Hash[N<<]; void UpDate(int r)
{
if(a[r].L!=a[r].R && (a[Lson].isCover && a[Rson].isCover))
a[r].isCover=true;
}
void BuildTree(int r, int L, int R)
{
a[r].L = L, a[r].R = R;
a[r].isCover = false; if(L==R)
return ; BuildTree(Lson, L, a[r].Mid());
BuildTree(Rson, a[r].Mid()+, R);
}
bool Insert(int r, int L, int R)
{
if(a[r].isCover) return false; if(a[r].L==L && a[r].R==R)
{
a[r].isCover=true;
return true;
} bool ans; if(R<=a[r].Mid())
ans = Insert(Lson, L, R);
else if(L>a[r].Mid())
ans = Insert(Rson, L, R);
else
{
bool lson = Insert(Lson, L, a[r].Mid());
bool rson = Insert(Rson, a[r].Mid()+, R); ans = lson|rson;
} UpDate(r); return ans;
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n, nh=;
scanf("%d", &n);
memset(s, , sizeof(s)); for(int i=; i<=n; i++)
{
scanf("%d%d", &s[i].L, &s[i].R);
Hash[nh++] = s[i].L, Hash[nh++]=s[i].L-;
Hash[nh++] = s[i].R, Hash[nh++]=s[i].R+;
} sort(Hash, Hash+nh);
nh = unique(Hash, Hash+nh) - Hash; BuildTree(, , nh); int ans=;
for(int i=n; i>; i--)
{
int L = lower_bound(Hash, Hash+nh, s[i].L) - Hash; // 返回是s[i].L的下标
int R = lower_bound(Hash, Hash+nh, s[i].R) - Hash; if(Insert(, L, R))
ans += ;
} printf("%d\n", ans);
}
return ;
}
(线段树)Mayor's posters --poj -- 2528的更多相关文章
- 线段树 Mayor's posters
甚至DFS也能过吧 Mayor's posters POJ - 2528 The citizens of Bytetown, AB, could not stand that the candidat ...
- Mayor's posters POJ - 2528(线段树 + 离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 74745 Accepted: 21574 ...
- Mayor's posters POJ - 2528 线段树区间覆盖
//线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algori ...
- Mayor's posters POJ - 2528 线段树(离散化处理大数?)
题意:输入t组数据,输入n代表有n块广告牌,按照顺序贴上去,输入左边和右边到达的地方,问贴完以后还有多少块广告牌可以看到(因为有的被完全覆盖了). 思路:很明显就是线段树更改区间,不过这个区间的跨度有 ...
- D - Mayor's posters POJ - 2528 离散化+线段树 区间修改单点查询
题意 贴海报 最后可以看到多少海报 思路 :离散化大区间 其中[1,4] [5,6]不能离散化成[1,2] [2,3]因为这样破坏了他们的非相邻关系 每次离散化区间 [x,y]时 把y+1点也加入 ...
- Mayor's posters POJ - 2528
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...
- 线段树 + 区间更新 + 模板 ---- poj 3468
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 59798 ...
- 线段树(成段更新) POJ 3468 A Simple Problem with Integers
题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...
- 线段树扫描线总结(POJ 1389)
扫描线算是线段树的一个比较特殊的用法,虽然NOIP不一定会考,但是学学还是有用的,况且也不是很难理解. 以前学过一点,不是很透,今天算是搞懂了. 就以这道题为例吧:嘟嘟嘟 题目的意思是在一个二维坐标系 ...
随机推荐
- JAVA中会存在内存泄露吗
所谓内存泄露就是指一个不再被程序使用的对象或变量一直被占据在内存中.java中有垃圾回收机制,它可以保证一对象不再被引用的时候,即对象编程了孤儿的时候,对象将自动被垃圾回收器从内存中清除掉.由于Jav ...
- servlet和JSP页面乱码问题
JSP和Servlet的中文乱码处理 前几天学习了JSP和Servlet中有关中文乱码的一些问题,写成了博客,今天进行更新一下.应该是可以解决日常的乱码问题了.现在作以下总结希望对需要的人有所帮助.我 ...
- Spring @Configuration
下面是一个典型的spring配置文件(application-config.xml): <beans> <bean id="orderService" class ...
- appcan更新
升级用到了config.xml文件中配置的‘更新地址‘所填写的url,此url开发者可任意配置自己的服务器地址* 当app执行uexWidget.checkUpdate()时,AppCan会请求上述u ...
- 消息 14607,级别 16,状态 1,过程 sp_send_dbmail,第 141 行 profile 名称无效
错误:消息 14607,级别 16,状态 1,过程 sp_send_dbmail,第 141 行profile 名称无效 原因: 用SA帐户是可以发送邮件的,但换了另外一个帐户后却提示以上错误. 解决 ...
- cf-Round542-Div2-C(暴力+DFS)
题目链接:http://codeforces.com/contest/1130/problem/C 思路: 利用DFS搜索(r1,c1)和(r2,c2)可到达的点的集合,分别存在a1,a2中,若a1= ...
- compression
compression - 必应词典 美[kəmˈpreʃ(ə)n]英[kəm'preʃ(ə)n] n.压缩:加压:压紧:浓缩 网络压迫:压力:加压包扎
- ios 打tag
修改spec文件的version: git commit -am"version 0.1.1" git push origin master -u git tag 0.1.1 gi ...
- php iframe 上传文件
我们通过动态的创建iframe,修改form的target,来实现无跳转的文件上传. 具体的实现步骤 1.捕捉表单提交事件 2.创建一个iframe 3.修改表单的target,指向iframe ...
- tp中引入js、css、img的问题
方法一: 直接把js.css.img放到网站公共目录/Public/下. 然后直接在模板文件中使用__PUBLIC__进行替换. 方法二: 在模块配置文件config.php中配置指定的路径,如下: ...