链接:

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的更多相关文章

  1. 线段树 Mayor's posters

    甚至DFS也能过吧 Mayor's posters POJ - 2528 The citizens of Bytetown, AB, could not stand that the candidat ...

  2. Mayor's posters POJ - 2528(线段树 + 离散化)

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

  3. Mayor's posters POJ - 2528 线段树区间覆盖

    //线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algori ...

  4. Mayor's posters POJ - 2528 线段树(离散化处理大数?)

    题意:输入t组数据,输入n代表有n块广告牌,按照顺序贴上去,输入左边和右边到达的地方,问贴完以后还有多少块广告牌可以看到(因为有的被完全覆盖了). 思路:很明显就是线段树更改区间,不过这个区间的跨度有 ...

  5. D - Mayor's posters POJ - 2528 离散化+线段树 区间修改单点查询

    题意 贴海报 最后可以看到多少海报 思路 :离散化大区间  其中[1,4] [5,6]不能离散化成[1,2] [2,3]因为这样破坏了他们的非相邻关系 每次离散化区间 [x,y]时  把y+1点也加入 ...

  6. Mayor's posters POJ - 2528

    The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...

  7. 线段树 + 区间更新 + 模板 ---- poj 3468

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 59798   ...

  8. 线段树(成段更新) POJ 3468 A Simple Problem with Integers

    题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...

  9. 线段树扫描线总结(POJ 1389)

    扫描线算是线段树的一个比较特殊的用法,虽然NOIP不一定会考,但是学学还是有用的,况且也不是很难理解. 以前学过一点,不是很透,今天算是搞懂了. 就以这道题为例吧:嘟嘟嘟 题目的意思是在一个二维坐标系 ...

随机推荐

  1. spark性能调优 数据倾斜 内存不足 oom解决办法

    [重要] Spark性能调优——扩展篇 : http://blog.csdn.net/zdy0_2004/article/details/51705043

  2. mysql转型

    1.将Int 转为varchar经常用 concat函数,比如concat(8,’0′) 得到字符串 ’80′2.将varchar 转为Int 用 cast(a as signed) a为varcha ...

  3. 149. Max Points on a Line (Array; Greedy)

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  4. 【英宝通Unity4.0公开课学习 】(五)47讲到75讲

    不知不觉今天都已经看了快30讲了,虽然很想快马加鞭地将后面的内容看完,但为了学习的质量,还是挺下来写一篇blog :) 这两天有些昏昏沉沉的,但感觉生活还安排得不错,原因找去找来觉得是没怎么开窗透气. ...

  5. 一个性能较好的JVM参数配置

    一个性能较好的web服务器jvm参数配置: -server//服务器模式-Xmx2g //JVM最大允许分配的堆内存,按需分配-Xms2g //JVM初始分配的堆内存,一般和Xmx配置成一样以避免每次 ...

  6. 设置网站默认用IE7打开

    head中加入以下内容 <meta http-equiv="X-UA-Compatible" content="IE=7" />

  7. [leetcode]318. Maximum Product of Word Lengths单词长度最大乘积

    Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...

  8. ImageView小技巧

    ImageView截取图片的方式 centerCrop:以中心点为基准 将图片的最短边与ImageView宽度匹配 其他部分裁掉centerInside: 以中心点为基准 将图片最长边 缩进控件去

  9. 如何利用jQuery post传递含特殊字符的数据【转】

    在jQuery中,我们通常利用$.ajax或$.post进行数据传递处理,但这里通常不能传递特殊字符,如:“<”.本文就介绍如何传递这种含特殊字符的数据. 1.准备页面和控制端代码 页面代码如下 ...

  10. WebApi是轻量级的,WCF是重量级的,可以Api调用WCF,更灵活

    WCF.WebAPI.WCFREST.WebService之间的区别 注明:转载 在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API.在 ...