POJ 2029 Get Many Persimmon Trees

#include <stdio.h>
#include <cstring>
const int maxn=101;
int c[maxn][maxn];
inline int lowbit(int x)
{
    return x&(-x);
}
void update(int x,int y)
{
    for(int i=x; i<=maxn; i+=lowbit(i))
        for(int j=y; j<=maxn; j+=lowbit(j))
            c[i][j]+=1;
}
int sum(int x,int y)
{
    int ans=0;
    for(int i=x; i>0; i-=lowbit(i))
        for(int j=y; j>0; j-=lowbit(j))
            ans+=c[i][j];
    return ans;
}
int main()
{
    int n,w,h,x,y,s,t;
    while(scanf("%d",&n)==1&&n)
    {
        memset(c,0,sizeof(c));
        scanf("%d%d",&w,&h);
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d",&x,&y);
            update(x,y);
        }
        scanf("%d%d",&s,&t);
        int ans=-1;
        for(int i=1; i<=w; i++)
            for(int j=1; j<=h; j++)
            {
                if(i+s-1>w||j+t-1>h) continue;
                int temp=sum(i+s-1,j+t-1)-sum(i-1,j+t-1)-sum(i+s-1,j-1)+sum(i-1,j-1);
                if(temp>ans) ans=temp;
            }
        printf("%d\n",ans);
    }
    return 0;
}

發佈了185 篇原創文章 · 獲贊 3 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章