思路:

大力出奇迹,先用二维树状数组存,然后暴力枚举

算某个矩形区域的值的示意图如下,代码在下面慢慢找...

代码:

#include<cstdio>
#include<map>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N = 1030+5;
int bit[N][N],n,m;
int lowbit(int x){
return x&(-x);
}
void update(int x,int y,int val){
for(int i = x;i <= n;i += lowbit(i)){
for(int j = y;j <= m;j += lowbit(j)){
bit[i][j] += val;
}
}
}
int sum(int x,int y){
int ret = 0;
for(int i = x;i > 0;i -= lowbit(i)){
for(int j = y;j > 0;j -= lowbit(j)){
ret += bit[i][j];
}
}
return ret;
}
int main(){
int q,x,y;
while(scanf("%d",&q) && q){
memset(bit,0,sizeof(bit));
scanf("%d%d",&n,&m);
while(q--){
scanf("%d%d",&x,&y);
update(x,y,1);
}
int S,T;
scanf("%d%d",&S,&T);
int x2,y2;
int MAX = -1;
for(int x1 = 1;x1 <= n-S+1;x1++){
for(int y1 = 1;y1 <= m-T+1;y1++){
x2 = x1 + S - 1;
y2 = y1 + T - 1;
int tmp = sum(x2,y2) - sum(x2,y1 - 1) - sum(x1 - 1,y2) + sum(x1 - 1,y1 -1);    //区域
MAX = tmp > MAX? tmp : MAX;
}
}
printf("%d\n",MAX);
}
return 0;
}

POJ 2029 (二维树状数组)题解的更多相关文章

  1. poj 2029 二维树状数组

    思路:简单树状数组 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...

  2. POJ 1195 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18489   Accepted: 8558 De ...

  3. poj 3378 二维树状数组

    思路:直接用long long 保存会WA.用下高精度加法就行了. #include<map> #include<set> #include<cmath> #inc ...

  4. poj 2155 (二维树状数组 区间修改 求某点值)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 33682   Accepted: 12194 Descript ...

  5. Mobile phones POJ - 1195 二维树状数组求和

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...

  6. POJ 2029 Get Many Persimmon Trees (二维树状数组)

    Get Many Persimmon Trees Time Limit:1000MS    Memory Limit:30000KB    64bit IO Format:%I64d & %I ...

  7. POJ 2029 Get Many Persimmon Trees(DP||二维树状数组)

    题目链接 题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树.输出数目 思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做. #include <stdio ...

  8. POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】

    <题目链接> 题目大意: 给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点. 解题分析:二维树状数组模板题. #include <cstdio ...

  9. POJ 2155 Matrix (二维树状数组)题解

    思路: 没想到二维树状数组和一维的比只差了一行,update单点更新,query求和 这里的函数用法和平时不一样,query直接算出来就是某点的值,怎么做到的呢? 我们在更新的时候不止更新一个点,而是 ...

随机推荐

  1. 菜鸟教程之工具使用——Git的基本使用

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/liushuijinger/article/details/37569907 Git是进来比較火的版本 ...

  2. Prometheus+Grafana+Altermanager搭建监控系统

    基本概念 Prometheus 时间序列化数据库,我的理解就是将数据打上标签,以时间维度存储.后面有机会在深入研究. Prometheus架构如下: Grafana Prometheus中存储的数据, ...

  3. [django]django的orm查询

    实体 实体 出版社 category 作者 tag 书 文章 先学习一下基础的增删查改 django orm增删改查: https://www.cnblogs.com/iiiiiher/article ...

  4. hdu1671Phone List(字典树)

    #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h&g ...

  5. PAT 1045 Favorite Color Stripe[dp][难]

    1045 Favorite Color Stripe (30)(30 分) Eva is trying to make her own color stripe out of a given one. ...

  6. [LeetCode] 733. Flood Fill_Easy tag: BFS

    An image is represented by a 2-D array of integers, each integer representing the pixel value of the ...

  7. [LeetCode] 496. Next Greater Element I_Easy tag: Stack

    You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of n ...

  8. C# Bulk Operations(转)

    转自http://blog.csdn.net/winnyrain/article/details/51240684 Overcome SqlBulkCopy Limitations with C# B ...

  9. mysql重做日志

    一.重做日志(redo log) 1.作用 确保事务的持久性. 防止在发生故障的时间点,尚有脏页未写入磁盘,在重启mysql服务的时候,根据redo log进行重做,从而达到事务的持久性这一特性. 2 ...

  10. Perl的变量及语境(一)

    Perl语言中的大部分语句表达式后都紧接一个分号,分隔不同的Perl语句. perl解释器能一次完成编译和运行这两个动作. perl通过一对反引号"``"来表示运行外部命令. 也可 ...