poj 2029 二维树状数组
思路:简单树状数组
#include<map> #include<set> #include<cmath> #include<queue> #include<cstdio> #include<vector> #include<string> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define pb push_back #define mp make_pair #define Maxn 120 #define Maxm 80002 #define LL __int64 #define Abs(x) ((x)>0?(x):(-x)) #define lson(x) (x<<1) #define rson(x) (x<<1|1) #define inf 0x7fffffff #define lowbit(x) (x&(-x)) #define Mod 1000000007 using namespace std; int c[Maxn][Maxn],w,h,n; void update(int x,int y) { int yy=y; while(x<=w){ y=yy; while(y<=h){ c[x][y]++; y+=lowbit(y); } x+=lowbit(x); } } int sum(int x,int y) { int sum=0,yy=y; while(x){ y=yy; while(y){ sum+=c[x][y]; y-=lowbit(y); } x-=lowbit(x); } return sum; } int main() { int n,i,j,x,y; while(scanf("%d",&n)!=EOF,n){ memset(c,0,sizeof(c)); scanf("%d%d",&w,&h); for(i=1;i<=n;i++){ scanf("%d%d",&x,&y); update(x,y); } scanf("%d%d",&x,&y); int ans=0; for(i=x;i<=w;i++){ for(j=y;j<=h;j++){ ans=max(ans,sum(i,j)-sum(i-x,j)-sum(i,j-y)+sum(i-x,j-y)); } } printf("%d\n",ans); } return 0; }