Test instructions: Give a h*w rectangle, give n coordinates, plant trees in these n coordinates, give a s*t size rectangle, ask how many trees can be obtained in this s*t rectangle.
A two-dimensional tree-like array, seeking to get the most out of the tree when, since h,w are not more than 500, direct violence
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A -typedefLong LongLL; - Const intINF = (1<< -)-1; the Const intMod=1000000007; - Const intmaxn=1005; - - intC[MAXN][MAXN]; + - intLowbit (intx) {returnX & (-x);} + A intSumintXinty) { at intret=0; - intY1; - while(X >0){ -y1=y; - while(Y1 >0){ -RET + = c[x][y1];y1-=lowbit (y1); in } -x-=lowbit (x); to } + returnret; - } the * voidAddintXintYintd) { $ intY1;Panax Notoginseng while(X <MAXN) { -y1=y; the while(Y1 <MAXN) { +C[X][Y1] + = d;y1+=lowbit (y1); A } thex+=lowbit (x); + } - } $ $ intMain () { - intN; - while(SCANF ("%d", &n)!=eof &&N) { theMemset (c,0,sizeof(c)); - intw,h;Wuyiscanf"%d%d",&w,&h); the while(n--){ - intu,v; Wuscanf"%d%d",&u,&v); -Add (V,u,1); About } $ intx, y; -scanf"%d%d",&x,&y); swap (x, y); - - intans=-1; A inttmp=0; + for(intI=1; I <=h;i++){ the for(intj=1; j<=w;j++){ -TMP = SUM (i+x-1, j+y-1)-sum (I-1, j+y-1)-sum (i+x-1, J-1) +sum (I-1, J-1); $Ans =Max (ans,tmp); the } the } theprintf"%d\n", ans); the } - return 0; in}
View Code
POJ 2029 Get Many persimmon Trees "two-dimensional tree-like array"