链接:

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. MySql PartionBy

    SELECT tableOld.*, if(@channelName = tableOld.channelName, @rank := @rank + 1, @rank := 1) AS rank, ...

  2. MySQL高级-索引

    1.索引是什么 索引(Index)是帮助MySQL高效获取数据的数据结构.可以得到索引的本质:索引是数据结构. 可以理解为“排好序的快速查找数据结构” 在数据之外,数据库系统还维护着满足特定查找算法的 ...

  3. html标签对应的英文原文(转载)

    标签  对应英文 说明 <!--> / 注释 <!DOCTYPE> document type 文档类型 <a> anchor 超链接 <abbr> a ...

  4. zoj1109-Language of FatMouse 【字典树】

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=109 Language of FatMouse Time Limit: 10 S ...

  5. Python3 range() 函数用法

    Python3 range() 函数用法  Python3 内置函数 Python3 range() 函数返回的是一个可迭代对象(类型是对象),而不是列表类型, 所以打印的时候不会打印列表. Pyth ...

  6. Asp.net中操作Excel的代码解析

    一 . 使用Excel对象模型创建Excel文档: 1.创建简单的文档 try { 3 //创建Excel程序对象 Microsoft.Office.Interop.Excel.Application ...

  7. 搜索旋转排序数组 II

    跟进“搜索旋转排序数组”,假如有重复元素又将如何? 一句话思路:不能二分,因为复杂度是n eg全是0,找一个1 class Solution { public boolean search(int[] ...

  8. [leetcode]314. Binary Tree Vertical Order Traversal二叉树垂直遍历

    Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bott ...

  9. [leetcode]283. Move Zeroes移零

    Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ ...

  10. Linux中chown、chmod、chgrp

    1.chgrp (转变文件所属用户组) chgrp(转变文件所属用户组)change group chgrp 用户组 文件名 ###便是这个格了.若是整个目次下的都改,则加-R参数用于递归. 如:ch ...