question: there are many people in the square. Now, I will give you a square with a side length of "R". The square shall have at most people that can be framed, including the border.
question:
# Include <algorithm >#include <iostream> using namespace STD; # define n 2010 # define L (u) (u * 2) # define R (u) (u * 2 + 1) # define max (A, B) (A> B? A: B) unsigned int y [N]; struct treenode {int L, R, V, add;} node [N * 3]; struct point {unsigned int X, Y; int V;} Point [N]; bool CMP (point & A, point & B) {if (. X = B. x) return. v> B. v; return. x <B. x;} int bfind (int l, int R, unsigned int key) {While (L <= r) {int mid = (L + r)/2; if (Y [Mid] = Key) return mid; If (Key <Y [Mid]) r = mid-1; else l = Mid + 1;} RET Urn-1;} void build (int u, int L, int R) {node [u]. L = L; node [u]. R = r; node [u]. V = node [u]. add = 0; If (L = r) return; int mid = (L + r)/2; build (L (u), L, mid ); build (R (u), Mid + 1, R);} void Update (int u, int L, int R, int Val) {If (L <= node [u]. L & node [u]. r <= r) {node [u]. add + = val; node [u]. V + = val; return;} If (node [u]. add! = 0) {node [L (u)]. add + = node [u]. add; node [L (u)]. V + = node [u]. add; node [R (u)]. add + = node [u]. add; node [R (u)]. V + = node [u]. add; node [u]. add = 0;} int mid = (node [u]. L + node [u]. r)/2; If (r <= mid) Update (L (u), L, R, Val); else if (L> mid) Update (R (u ), l, R, Val); else {Update (L (u), L, mid, Val); Update (R (u), Mid + 1, R, Val );} node [u]. V = max (node [L (u)]. v, node [R (u)]. V );} Int main () {int N, R, X, Y, I, j; while (scanf ("% d", & N, & R )! = EOF) {for (I = 1; I <= N; I ++) {scanf ("% d", & X, & Y ); point [I]. X = x; point [I]. y = y; point [I]. V = 1; y [I] = y;} for (I = 1; I <= N; I ++) {point [I + N]. X = point [I]. X + R; point [I + N]. y = point [I]. y; point [I + N]. V =-1; y [I + N] = point [I]. Y + R;} Sort (point + 1, point + 1 + N * 2, CMP); sort (Y + 1, Y + 1 + N * 2 ); for (I = j = 1; I <= N * 2; I ++) {If (Y [J]! = Y [I]) y [++ J] = Y [I];} build (1, 1, J); int L, R, ANS = 0; for (I = 1; I <= N * 2; I ++) {L = bfind (1, J, point [I]. y); r = bfind (1, J, point [I]. Y + r); Update (1, L, R, point [I]. v); If (ANS <node [1]. v) ans = node [1]. v;} printf ("% d \ n", ANS);} return 0 ;}