Test instructions: Move a rectangle so that the rectangle contains as many points as possible.
Idea: Split a point into two events, one in (weighted to 1) one out (weighted to 1), all points sorted by X, then scanned, for each X, a sliding window to calculate the maximum value, and then move the scan line. A tree-like array can be implemented.
The above method is not optimal, and the best known approach is to compress a rectangle into a single point, and a point to extend to a line and update the Y+h interval when encountering a point. (Segment Tree lazy operation), then ask for the maximum value of the point (rectangle) on the line segment tree. You must use a line segment tree to reduce the complexity of the time.
Similar ideas to the topic Seoul2007 La3905,meteor Meteor
Only the tree-shaped array version is written, given that the scan line needs to be further studied and treated more.
At that time do know is a line tree, unfortunately I do not write scan line, previously tried to write, hang, the foundation needs to be strengthened.
#include <cstdio>#include<algorithm>using namespacestd;Const intMaxh =40000+5;Const intMAXN =10000+5;intC[maxh];#defineLowbit (x) (x& (×))voidAddintXintv) { while(x <=40001) {C[x]+ = V; X + =lowbit (x); }}intSumintx) { intres =0; while(x>0) {res+ = C[x]; X-=lowbit (x); } returnRes;}structpoint{intx, y; BOOL operator< (ConstPoint & RHS)Const { returnX <rhs.x; }}POI[MAXN];intMain () {//freopen ("In.txt", "R", stdin); intN; while(~SCANF ("%d", &n) && n>0){ intw,h; scanf ("%d%d",&w,&H); for(inti =0; i < N; i++) {scanf ("%d%d",&poi[i].x,&poi[i].y); Poi[i].y+=20001; } sort (Poi,poi+N); intL, R; L = R =0; intAns =0; while(r<N) { while(poi[r].x-poi[l].x <= W && r<o) {Add (Poi[r++].Y,1); } for(inti =1, Sz =40001H I <= sz; i++) {ans= Max (Ans,sum (i+h)-sum (i-1)); } if(r<N) while(Poi[r].x-poi[l].x >W) {Add (Poi[l++].y,-1); }} printf ("%d\n", ans); while(l<N) {Add (Poi[l++].y,-1); } } return 0;}
HDU 5091 Beam Cannon