【HDU - 5091】Beam Cannon(线段树,扫描线)

题干:

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];

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440579.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql的传播特性_spring事务传播特性和mysql事务隔离级别

spring事务的传播特性--7种REQUIRED支持当前事务&#xff0c;如果没有事务会创建一个新的事务SUPPORTS支持当前事务&#xff0c;如果没有事务的话以非事务方式执行MANDATORY(强制性)支持当前事务&#xff0c;如果没有事务抛出异常REQUIRES_NEW创建一个新的事物并挂起当前事务NO…

【 HDU - 5093】Battle ships(匈牙利算法,二分图匹配)

题干&#xff1a; Dear contestant, now you are an excellent navy commander, who is responsible of a tough mission currently. Your fleet unfortunately encountered an enemy fleet near the South Pole where the geographical conditions are negative for both si…

【HDU - 5090】Game with Pearls (匈牙利算法,二分图匹配)

题干&#xff1a; Tom and Jerry are playing a game with tubes and pearls. The rule of the game is: 1) Tom and Jerry come up together with a number K. 2) Tom provides N tubes. Within each tube, there are several pearls. The number of pearls in each tube i…

qt同时连接oracle和mysql_QT连接Oracle和Mysql的详细步骤,已成功~!

近几天一直在整QT的数据库连接这一块。因为QT是开源的&#xff0c;所以涉及的连接Oracle及Mysql的驱动都必须自己编译生成。通过不断的测试、调试&#xff0c;终于把QT连接Oracle和Mysql的驱动编译生成好了。QT环境&#xff1a;Qt 4.6.0打开Qt Command Prompt&#xff0c;开始菜…

【POJ - 2632】Crashing Robots(模拟)

题干&#xff1a; In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of course, all warehouses are rectangular, and all robots occup…

一台linux上运行多个mysql_linux下同时运行多个mysql

来自网络&#xff0c;感谢开源&#xff0c;感谢分享通过rpm安装mysql&#xff0c;测试版本5.1.481、在linux下通过:#useradd multi -g mysql -s /sbin/nologin添加一个multi用户&#xff0c;并加入到mysql组#passwd multi给multi用户添加密码&#xff0c;这里设置的密码为multi…

【SPOJ - QTREE2】Query on a tree II(LCA,倍增)

题干&#xff1a; You are given a tree (an undirected acyclic connected graph) with N nodes, and edges numbered 1, 2, 3...N-1. Each edge has an integer value assigned to it, representing its length. We will ask you to perfrom some instructions of the foll…

pandownload用户未登录_Pandownload再度复活,下载速度飙升到10MB/s以上

PanDownload再度复活版&#xff0c;此版镜像服务器由新城旧梦维护卢本伟修改版&#xff0c;基本都是维持在10M/S的下载速度&#xff0c;如果你的宽带够大&#xff0c;下载速度会更快&#xff0c;无需安装即可免费使用&#xff0c;但是需要登陆才能下载。(Pandownload卢本伟修改…

【蓝桥杯 - 试题】立方尾不变(tricks,快速取出一个数字的后n位)

题干&#xff1a; 有些数字的立方的末尾正好是该数字本身。 比如&#xff1a;1,4,5,6,9,24,25,.... 请你计算一下&#xff0c;在10000以内的数字中&#xff08;指该数字&#xff0c;并非它立方后的数值&#xff09;&#xff0c;符合这个特征的正整数一共有多少个。 请提交该…

momentjs转换格式_Moment.js+Vue过滤器的使用,各种时间格式转换为YYYY-MM-DD HH:mm:ss格式...

前言这篇文章将Moment.js与vue过滤器连用。如果不会过滤器的朋友&#xff0c;可以先看这篇文章vue过滤器一、Moment.js是什么&#xff1f;Moment.js是JavaScript 日期处理类库。使用场景&#xff1a;vue项目中经常需要将时间戳转换为各种时间格式再显示。二、使用步骤1.安装这里…

【HDU - 1943】Ball bearings(几何问题)

题干&#xff1a; The Swedish company SKF makes ball bearings. As explained by Britannica Online, a ball bearing is “one of the two types of rolling, or anti friction, bearings (the other is the roller bearing). Its function is to connect two machine mem…

mysql显示修改密码_MySQL修改密码

第一种方式&#xff1a;最简单的方法就是借助第三方工具Navicat for MySQL来修改&#xff0c;方法如下&#xff1a;1、登录mysql到指定库&#xff0c;如&#xff1a;登录到test库。2、然后点击上方“用户”按钮。3、选择要更改的用户名&#xff0c;然后点击上方的“编辑用户”按…

【POJ - 2486】Apple Tree (树形背包,dp)

题干&#xff1a; Wshxzt is a lovely girl. She likes apple very much. One day HX takes her to an apple tree. There are N nodes in the tree. Each node has an amount of apples. Wshxzt starts her happy trip at one node. She can eat up all the apples in the no…

mysql 磁盘组_有效管理 ASM 磁盘组空间

ORA-15041: diskgroup space exhausted 对您的数据库环境的直接和间接影响&#xff1f;与 ASM 磁盘组相关的磁盘空间问题和 ORA-15041 错误会ORA-15041: diskgroup space exhausted 对您的数据库环境的直接和间接影响&#xff1f;与 ASM 磁盘组相关的磁盘空间问题和 ORA-15041 …

【HDU - 1561】The more, The Better(树形背包,dp,依赖背包问题与空间优化,tricks)

题干&#xff1a; ACboy很喜欢玩一种战略游戏&#xff0c;在一个地图上&#xff0c;有N座城堡&#xff0c;每座城堡都有一定的宝物&#xff0c;在每次游戏中ACboy允许攻克M个城堡并获得里面的宝物。但由于地理位置原因&#xff0c;有些城堡不能直接攻克&#xff0c;要攻克这些…

mysql判断域为空_MySQL EXPLAIN 字段说明

id查询或关联查询的顺序。如果没有子查询且只有一个查询&#xff0c;则为一个常数 1&#xff0c;表示第一步&#xff1b;如果有子查询&#xff0c;则子查询为 1&#xff0c;父查询为 2&#xff1b;相同的 id 查询顺序为自上而下&#xff1b;如果有子查询&#xff0c;不同 id 值…

【CodeForces - 618A】Slime Combining(二进制,思维)

题干&#xff1a; Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other…

mysql索引技术_MySQL索引类型

首先请查看不同引擎支持的索引类型&#xff1a;存储引擎简介 。聚集索引和非聚集索引概念见&#xff1a;聚集索引与非聚集索引 和 聚集索引 。 覆盖索引见&#xff1a;覆盖索引 。1. InnoDB的每一个表都会有一个聚集索引(第一索引&#xff0c;主键索引)。InnoDB按照主键进行聚集…

【CodeForces - 616C 】The Labyrinth点石成金(并查集,dfs)

题干&#xff1a; 小O无意间发现了一张藏宝图&#xff0c;它跟随藏宝图的指引来到了一个宫殿&#xff0c;宫殿的地板被分成了n*m块格子&#xff0c;每个格子上放置了金子或者石头 藏宝图告诉小O&#xff0c;它可以选择一块石头变成金子&#xff0c;并且带走与变化后的金子联通…

mysql连接方式左联_数据库中的左连接(left join)和右连接(right join)区别 | 改变自己...

Left Join / Right Join /inner join相关关于左连接和右连接总结性的一句话&#xff1a;左连接where只影向右表&#xff0c;右连接where只影响左表。Left Joinselect * from tbl1 Left Join tbl2 where tbl1.ID tbl2.ID左连接后的检索结果是显示tbl1的所有数据和tbl2中满足whe…