HDOJ 5091 Beam Cannon 扫描线
线段树+扫描线:
我们用矩形的中心点来描写叙述这个矩形,然后对于每一个敌舰,我们建立一个矩形中心的活动范围,即矩形中心在该范围内活动就能够覆盖到该敌舰.那么我们要求的问题就变成了:随意一个区域(肯定也是矩形的)最多能被矩形覆盖的最大值.
Beam Cannon
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 159 Accepted Submission(s): 59
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.
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.
2 3 4
0 1
1 0
3 1 1
-1 0
0 1
1 0
-1
2
2
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath> using namespace std; const int maxn=30100; #define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 struct SEG
{
double y1,y2,h;
int d;
}seg[maxn<<2]; bool cmp(SEG a,SEG b)
{
if(a.h==b.h) return a.d>b.d;
return a.h<b.h;
} int add[maxn<<2],mx[maxn<<2];
int n,sn;
double W,H; double Y[maxn<<2];
int ny; void push_up(int rt)
{
mx[rt]=max(mx[rt<<1],mx[rt<<1|1]);
} void push_down(int rt)
{
if(add[rt])
{
mx[rt<<1]+=add[rt]; mx[rt<<1|1]+=add[rt];
add[rt<<1]+=add[rt]; add[rt<<1|1]+=add[rt];
add[rt]=0;
}
} void update(int L,int R,int D,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
add[rt]+=D;
mx[rt]+=D;
return ;
}
push_down(rt);
int m=(l+r)/2;
if(L<=m) update(L,R,D,lson);
if(R>m) update(L,R,D,rson);
push_up(rt);
} int main()
{
while(scanf("%d",&n)!=EOF&&n>0)
{
scanf("%lf%lf",&W,&H);
sn=0; ny=0;
for(int i=0;i<n;i++)
{
double x,y;
scanf("%lf%lf",&x,&y);
seg[sn++]=(SEG){y-H/2,y+H/2,x-W/2,1};
seg[sn++]=(SEG){y-H/2,y+H/2,x+W/2,-1};
Y[ny++]=y-H/2; Y[ny++]=y+H/2;
} sort(seg,seg+sn,cmp);
sort(Y,Y+ny);
ny=unique(Y,Y+ny)-Y; memset(add,0,sizeof(add));
memset(mx,0,sizeof(mx)); int ans=0;
for(int i=0;i<sn;i++)
{
int y1=lower_bound(Y,Y+ny,seg[i].y1)-Y+1;
int y2=lower_bound(Y,Y+ny,seg[i].y2)-Y+1;
update(y1,y2,seg[i].d,1,ny,1);
ans=max(ans,mx[1]);
}
printf("%d\n",ans);
}
return 0;
}
HDOJ 5091 Beam Cannon 扫描线的更多相关文章
- 线段树+扫描线 HDOJ 5091 Beam Cannon(大炮)
题目链接 题意: 给出若干个点的坐标,用一个W*H的矩形去覆盖,问最多能覆盖几个点. 思路: 这是2014上海全国邀请赛的题目,以前写过,重新学习扫描线.首先把所有点移到第一象限([0, 40000] ...
- hdu 5091 Beam Cannon(扫描线段树)
题目链接:hdu 5091 Beam Cannon 题目大意:给定N个点,如今要有一个W∗H的矩形,问说最多能圈住多少个点. 解题思路:线段的扫描线,如果有点(x,y),那么(x,y)~(x+W,y+ ...
- HDU 5091 Beam Cannon (扫描线思想)
题意:移动一个矩形,使矩形内包含的点尽量多. 思路:把一个点拆成两个事件,一个进(权值为1)一个出(权值为-1),将所有点按照x排序,然后扫描,对于每个x,用一个滑窗计算一下最大值,再移动扫描线.树状 ...
- hdu 5091 Beam Cannon
题目大意: 有n个点(n<=10000),点的坐标绝对值不超过20000,然后问你用一个w*h(1<=w,h<=40000)的矩形,矩形的边平行于坐标轴,最多能盖住多少个点. 刘汝佳 ...
- [POI 2001+2014acm上海邀请赛]Gold Mine/Beam Cannon 线段树+扫描线
Description Byteman, one of the most deserving employee of The Goldmine of Byteland, is about to re ...
- hdu 5091(线段树+扫描线)
上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include &l ...
- [线段树]HDOJ5091 Beam Cannon
题意:给n, w, h (1 <= N <= 10000,1 <= W <= 40000,1 <= H <= 40000) $w\times h$是可以射到的范围 ...
- HDU 5091 线段树扫描线
给出N个点.和一个w*h的矩形 给出N个点的坐标,求该矩形最多能够覆盖多少个点 对每一个点point(x.y)右边生成相应的点(x+w,y)值为-1: 纵向建立线段树,从左到右扫描线扫一遍.遇到点则用 ...
- HDU 5091---Beam Cannon(线段树+扫描线)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...
随机推荐
- Python Jquery学习
jquery调用方法: $(css的选择器).操作函数 语法格式: 操作函数: html 修改内容 点击button键后,jquery就会变为bootstrap 当然里面也可以进行判断,实现 ...
- windows phone 网络开发三部曲(一)各种包的各种抓法
首先感谢大家对我上一篇博客的支持,让我也体验了一把上榜的感觉. 这无疑是对我这个刚刚打算,认真写写博客的人的莫大的鼓励,再次感谢(鞠躬)!! 接下来想和大家分享一些关于windows phone网络开 ...
- python基础-面向对象(装饰器)
属性: @property @method_name.setter @method_name.deleter 三个标签都是放在方法的上面来使用,且方法名要和后续使用的 变量名字相一 ...
- 有关C语言指针访问问题
C语言指针访问问题今天有了一些理解. char *p; char *q; char k[10000]; 我之前一直以为他们两个一样用,因为之前看到说k也是一个地址,我忽略了后面的一句话,k是连续的一段 ...
- JavaWeb基础(HTML)
代码改变世界 HTML HTML是指超本标记语言,它不是编程语言,而是一种标记语言.标记语言是一套标记标签,HTML使用标记标签来描述网页,用以定义如何在页面上展示信息. 1.HTML标签 HTML标 ...
- [TyvjP1519] 博彩游戏(AC自动机 + DP)
传送门 和bzoj1030一个德性 #include <queue> #include <cstdio> #include <cstring> #define N ...
- BZOJ 2431: [HAOI2009]逆序对数列【dp】
Description 对于一个数列{ai},如果有i<j且ai>aj,那么我们称ai与aj为一对逆序对数.若对于任意一个由1~n自然数组成的数列,可以很容易求出有多少个逆序对数.那么逆序 ...
- ElasticSearch中Date
ElasticSearch中有时会想要通过索引日期来筛选查询的数据,此时就需要用到日期数学表达式. 比如现在的时间是2024年3月22日中午12点.utc 注意,如果是中国的时间需要加上8个小时! 表 ...
- Chrome中输入框默认样式移除
Chrome中输入框默认样式移除 在chrome浏览器中会默认给页面上的输入框如input.textarea等渲染浏览器自带的边框效果 IE8中效果如下: Chrome中效果如下: 这在我们未给输 ...
- angular中的this指向问题
this是指向当前$scope的. 例如在ng-click的使用中,this是指向当前的$scope而并不是dom元素的. 我们可以使用this的一些方法和属性 我们打印一下this就会发现,this ...