题干:

Recently, the γ galaxies broke out Star Wars. Each planet is warring for resources. In the Star Wars, Planet X is under attack by other planets. Now, a large wave of enemy spaceships is approaching. There is a very large Beam Cannon on the Planet X, and it is very powerful, which can destroy all the spaceships in its attack range in a second. However, it takes a long time to fill the energy of the Beam Cannon after each shot. So, you should make sure each shot can destroy the enemy spaceships as many as possible.

To simplify the problem, the Beam Cannon can shot at any area in the space, and the attack area is rectangular. The rectangle parallels to the coordinate axes and cannot rotate. It can only move horizontally or vertically. The enemy spaceship in the space can be considered as a point projected to the attack plane. If the point is in the rectangular attack area of the Beam Cannon(including border), the spaceship will be destroyed.

Input

Input contains multiple test cases. Each test case contains three integers N(1<=N<=10000, the number of enemy spaceships), W(1<=W<=40000, the width of the Beam Cannon’s attack area), H(1<=H<=40000, the height of the Beam Cannon’s attack area) in the first line, and then N lines follow. Each line contains two integers x,y (-20000<=x,y<=20000, the coordinates of an enemy spaceship).

A test case starting with a negative integer terminates the input and this test case should not to be processed.

Output

Output the maximum number of enemy spaceships the Beam Cannon can destroy in a single shot for each case.

Sample Input

2 3 4
0 1
1 0
3 1 1
-1 0
0 1
1 0
-1

Sample Output

2
2

题目大意:

给你一个矩形的宽度和长度,然后给你一些点的坐标,让你输出这个矩形最多能覆盖多少个点。

解题报告:

类似扫描线的思想,将一条边拆成两条边,权值分别为1和-1。

AC代码1:(其实这里的.f,用laz比较合适)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX = 2e5 + 5;
struct Node {int x,y;int f;bool operator < (const Node &a)const{if(y==a.y) return f<a.f;return y<a.y;}
} node[MAX];
struct TREE {int l,r;int f,val;
} tree[400005 * 16];//???????????????????
void pushdown(int cur) {if(tree[cur].f == 0) return;int tmp = tree[cur].f;tree[cur].f = 0;tree[cur*2].f += tmp;tree[cur*2+1].f += tmp;tree[cur*2].val += tmp;tree[cur*2+1].val += tmp;
}
void build(int l,int r,int cur) {tree[cur].l=l,tree[cur].r=r;tree[cur].f = tree[cur].val = 0;if(l == r) return;int m = (l+r)>>1;build(l,m,cur*2);build(m+1,r,cur*2+1);
}
void update(int pl,int pr,int val,int cur) {if(pl <= tree[cur].l && pr >= tree[cur].r) {//pushup(cur);tree[cur].f += val;tree[cur].val += val;return ;}pushdown(cur);if(tree[cur*2].r >= pl) update(pl,pr,val,cur*2);if(tree[cur*2+1].l <= pr) update(pl,pr,val,cur*2+1);//pushup(cur);tree[cur].val = max(tree[cur*2].val,tree[cur*2+1].val);
}
int main()
{int n,W,H;while(cin>>n) {if(n == -1) break;cin>>W>>H;for(int a,b,i = 1; i<=2*n; i+=2) {scanf("%d%d",&a,&b);a+=20005;node[i].x=a;node[i+1].x=a;node[i].y=b;node[i+1].y=b+H+1;node[i].f=1;node[i+1].f=-1;}sort(node+1,node+2*n+1);build(1,10005*8,1);int ans = 0;for(int i = 1; i<=2*n; i++) {update(node[i].x,node[i].x + W,node[i].f,1);ans = max(ans,tree[1].val);}printf("%d\n",ans);   }return 0 ;
}

AC代码3:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX = 2e5 + 5;
struct Node {int x,y;int f;bool operator < (const Node &a)const{return x<a.x;}
} node[MAX];
struct TREE {int l,r;int f,val;
} tree[400005 * 16];//???????????????????
void pushdown(int cur) {if(tree[cur].f == 0) return;int tmp = tree[cur].f;tree[cur].f = 0;tree[cur*2].f += tmp;tree[cur*2+1].f += tmp;tree[cur*2].val += tmp;tree[cur*2+1].val += tmp;
}
void build(int l,int r,int cur) {tree[cur].l=l,tree[cur].r=r;tree[cur].f = tree[cur].val = 0;if(l == r) return;int m = (l+r)>>1;build(l,m,cur*2);build(m+1,r,cur*2+1);
}
void update(int pl,int pr,int val,int cur) {if(pl <= tree[cur].l && pr >= tree[cur].r) {//pushup(cur);tree[cur].f += val;tree[cur].val += val;return ;}pushdown(cur);if(tree[cur*2].r >= pl) update(pl,pr,val,cur*2);if(tree[cur*2+1].l <= pr) update(pl,pr,val,cur*2+1);//pushup(cur);tree[cur].val = max(tree[cur*2].val,tree[cur*2+1].val);
}
int main()
{int n,W,H;while(cin>>n) {if(n == -1) break;cin>>W>>H;for(int a,b,i = 1; i<=2*n; i+=2) {scanf("%d%d",&a,&b);b+=20000;node[i].x=a;node[i+1].x=a+W+1;node[i].y=b;node[i+1].y=b;node[i].f=1;node[i+1].f=-1;}sort(node+1,node+2*n+1);build(0,10005*8,1);int ans = 0;for(int i = 1; i<=2*n; i++) {update(node[i].y,node[i].y + H,node[i].f,1);ans = max(ans,tree[1].val);}printf("%d\n",ans);   }return 0 ;
}

AC代码4:(其实排序来说最标准的应该是这样)

struct Node {int x,y;int f;bool operator < (const Node &a)const{if(x==a.x) return f<a.f;return x<a.x;}
} node[MAX];

【HDU - 5091】Beam Cannon(线段树,扫描线)相关推荐

  1. hdu 1542 Atlantis (线段树+扫描线)

    http://acm.hdu.edu.cn/showproblem.php?pid=1542 单纯的线段树+扫描线求面积并,需要离散化. code: #include <cstdlib> ...

  2. HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)

    版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...

  3. 线段树扫描线求矩形周长详解

    线段树扫描线求矩形周长详解 原创 wucstdio 最后发布于2018-04-24 16:12:09 阅读数 841 收藏 发布于2018-04-24 16:12:09 版权声明:本文为博主原创文章, ...

  4. hdu3255 线段树扫描线求体积

    题意:       给你n个矩形,每个矩形上都有一个权值(该矩形单位面积的价值),矩形之间可能重叠,重叠部分的权值按照最大的算,最后问这n个矩形组成的图形的最大价值. 思路:       线段树扫描线 ...

  5. hdu1542 线段树扫描线求矩形面积的并

    题意:       给你n个正方形,求出他们的所占面积有多大,重叠的部分只能算一次. 思路:       自己的第一道线段树扫描线题目,至于扫描线,最近会写一个总结,现在就不直接在这里写了,说下我的方 ...

  6. bzoj 1645: [Usaco2007 Open]City Horizon 城市地平线(线段树扫描线)

    1645: [Usaco2007 Open]City Horizon 城市地平线 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 732  Solved: ...

  7. 亚特兰蒂斯【线段树+扫描线+离散化】

    亚特兰蒂斯[线段树+扫描线+离散化] POJ1151.ACwing247 题目: 有几个古希腊书籍中包含了对传说中的亚特兰蒂斯岛的描述. 其中一些甚至包括岛屿部分地图. 但不幸的是,这些地图描述了亚特 ...

  8. 2016 UESTC Training for Data Structures F - 郭大侠与“有何贵干?” CDOJ 1335 线段树 扫描线 离散化

    F - 郭大侠与"有何贵干?" 就是给一个三维空间,和N个长方体,问覆盖K次的体积 x和y都是1e9,但是z是[1,3],所以可以把这个分为两个二维平面,求被覆盖K次的面积,最后加 ...

  9. hdu 3397 Sequence operation(线段树,lazy,区间合并)

    hdu 3397 Sequence operation 线段树lazy和区间合并结合的一个题,相当于几个题集中到一起嘛,分开想就好了 0,1,2操作都要lazy,2的异或操作找到每一只含1或只含0的区 ...

  10. hdu 3265 线段树扫描线(拆分矩形)

    题意:        给你n个矩形,每个矩形上都有一个矩形的空洞,所有的矩形都是平行于x,y轴的,最后问所有矩形的覆盖面积是多少. 思路:       是典型的矩形覆盖问题,只不过每个矩形上多了一个矩 ...

最新文章

  1. FlasCC例子研究之Animation
  2. 深度学习经典数据集汇总
  3. Python Excel 操作 | xlrd+xlwt 模块笔记
  4. MATLAB之简谐信号声音的生成及其调制性
  5. html中源文件回车效果无效,网页制作使用教程第2节初级.ppt
  6. linux之nl命令
  7. Win32 一个helloworld对话框
  8. C++中没有定义类的引用。
  9. Eclipse连接到My sql数据库之前操作
  10. 嵩天python笔记_Python学习笔记
  11. Spring Cloud 启动Eureka的Client(客户端)时,项目一启动就停止,控制台无任何报错信息
  12. 润乾报表不显示的分析原因
  13. mysql不识别生僻字_MySQL生僻字插入失败怎么办
  14. 深度学习大神Hinton推翻自己30年的学术成果另造新世界
  15. 一名南京985AI硕士,CSDN博客专家
  16. 怎么使用systemctl启动rabbitmq_光纤激光切割机已经很久没有使用了。再次重新启动它,该怎么办?...
  17. python编译安装没有c扩展_pybind11—python C/C++扩展编译
  18. 树莓派3b+指南(二十二)暴力解决默认声卡设置失效问题
  19. 利用python对股票商誉进行排名分析,防止踩雷
  20. Big Sur菜单栏颜色遭吐槽?如何将Big Sur菜单栏调成暗黑模式

热门文章

  1. 深度学习04-RNN
  2. [剑指offer]面试题第[45]题[JAVA][把数组排成最小的数][快排][ Comparator][PriorityQueue]
  3. [剑指offer][JAVA]面试题[第23题][合并K个排序链表][分治][优先队列]
  4. php 强制刷新一次,强制浏览器使用PHP刷新所有内容
  5. 脚本启动慢_Linux 常用运维脚本,建议收藏
  6. jedispool redis哨兵_Redis详解(九)------ 哨兵(Sentinel)模式详解
  7. 计算机网络原理关于实验中几个指令使用的复习——网络层
  8. java knn分类_返回2个或更多最近邻居的KNN算法
  9. android socket 发送byte_如何正确地创建和销毁网络通讯程序中的Socket类的对象实例...
  10. python while九九乘法表儿歌_python使用while循环实现九九乘法表