# Hdoj 5091 beam cannon scanning line

Source: Internet
Author: User

Line Segment tree + scanning line:

We use the center point of the rectangle to describe this rectangle. Then, for each enemy ship, we create an active range of the rectangular center, that is, the rectangular center will be able to overwrite the enemy ship within this range. the question we need becomes: Any region (which must be a rectangle) has the maximum value that can be covered by a rectangle.

Beam cannon Time Limit: 3000/1500 MS (Java/others) memory limit: 65536/65536 K (Java/Others)
Total submission (s): 159 accepted submission (s): 59

Problem descriptionrecently, the gamma 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 shocould make sure each shot can destroy the enemy spaceships as stored 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.
Inputinput 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 shocould not to be processed.
Outputoutput the maximum number of enemy spaceships the beam cannon can destroy in a single shot for each case.
Sample Input
`2 3 40 11 03 1 1-1 00 11 0-1`

Sample output
`22`

Source2014 Shanghai national invitational competition-reproduction of the questions (thanks to Shanghai University for providing the questions)

`#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|1struct 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 scanning line

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.