链接:

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. unity 加载读取外部XML

    cfg.xml <rootNode> <category name="网站"> <item name="mainPage"> ...

  2. zookeeper 初步学习

    配置文件: tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳. dataDir:顾名思义就是 ...

  3. Oracle to_date()函数的用法《转载》

    to_date()是Oracle数据库函数的代表函数之一,下文对Oracle to_date()函数的几种用法作了详细的介绍说明, 原文地址:http://database.51cto.com/art ...

  4. for循环计算阶乘的和,for循环计算阶乘倒数的和

    计算阶乘的和 //阶乘的和,5!+4!+3!+2! int a = 5; for(int b = 4; b > 0; b--) { a = a * b; } //先定义好最大数的阶乘是多少 in ...

  5. 人机大战中AlphaGo及其执子人黄士杰

    2016年3月9日注定要写入围棋界的历史.IT界的历史以及科学界的历史.当天,韩国著名围棋棋手李世石VS谷歌AlphaGo的人机大战赛在韩国首尔举行.对弈的一方为拥有1200多个处理器的谷歌人工智能系 ...

  6. keras—多层感知器MLP—MNIST手写数字识别

    一.手写数字识别 现在就来说说如何使用神经网络实现手写数字识别. 在这里我使用mind manager工具绘制了要实现手写数字识别需要的模块以及模块的功能:  其中隐含层节点数量(即神经细胞数量)计算 ...

  7. swagger ui js 错误:Failed to execute 'serializeToString' on 'XMLSerializer': parameter 1 is not of type 'Node'.

    经过排查,引发此错误的原因是,表中有一个字段名称为“NodeName”,应该是在前台xml解析时引发冲突所致.我的解决办法是: 修改列名,修改映射. 如下: [Column("NodeNam ...

  8. Laravel5.4 Oauth2.0认证应用 API 实战!

    项目初始化 新建项目 lukeyans-MacBook-Pro:laravel lukeyan$ laravel new laravel_demo 添加laravel自带的Passport服务 luk ...

  9. 并发编程(四)TaskFuture

    并发编程(四)TaskFuture ExecutorService executorService = Executors.newSingleThreadExecutor(); Future<O ...

  10. centos 安装或更新最新版本软件包(git python etc)的方法 SCL IUS

    使用centos 经常发现官方提供的软件包版本过低,很多时候大家会选择下载源码自行编译,带来了很多麻烦. centos安装最新版本软件包,例如git,python等,可以通过红帽官方提供的softwa ...