zoukankan      html  css  js  c++  java
  • 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
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    多个表单项的动态校验
    js遍历循坏二维数组,显示天气情况
    纯css3 实现的焦点图
    实现元素水平和垂直居中的问题
    简易商品购物车
    用jquery的animate动画做成的左侧菜单伸缩
    MongoDB聚合
    NoSQL介绍
    MongoDB索引
    数据库索引简介
  • 原文地址:https://www.cnblogs.com/wangfang20/p/3298752.html
Copyright © 2011-2022 走看看