思路:

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

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

代码:

#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. Monkey and Banana---hdu1069(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 题意就是给你n种长方体每种类型不限制个数,然后我们把它们一个个堆起来,并且要满足下面的要比上面的 ...

  2. express 默认模板引擎

    使用express -t ejs microblog创建出来的居然不是ejs项目,而是jade项目.现在的版本已经没有-t这个命令了,改为express -e microblog.运行完之后,根据提示 ...

  3. SpringBoot @Transactional声明事务无效问题

    查看系统支持的存储引擎:show engines; 查看表使用的引擎:show table status from db_name where name='table_name'; 修改表引擎方法:  ...

  4. sdut2613(This is an A+B Problem)大数加法(乘法)

    #include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>u ...

  5. PAT 1074 Reversing Linked List[链表][一般]

    1074 Reversing Linked List (25)(25 分) Given a constant K and a singly linked list L, you are suppose ...

  6. openstack 部署笔记--基本环境准备

    基础信息 配置:centos7.3 8G内存 4核处理器  单网卡 控制节点IP:192.168.15.243 计算节点IP:192.168.15.238 openstack 版本:ocata 配置信 ...

  7. openstack部署心得

    官方文档:https://docs.openstack.org/ 个别版本有中文 不要轻易尝试最新版本 新版本刚推出一般存在不少BUG或者文档没有更新,按照文档配置就是不能成功.推荐尝试最新版本的上一 ...

  8. javascript实现unicode与字符互相转换

    javascript实现unicode与字符互相转换. <script language="javascript">  //手机检测  function checkMo ...

  9. javascript 获取元素样式的方法

    javascript 获取元素样式常用方法. Javascript获取CSS属性值方法:getComputedStyle和currentStyle  1 .对于元素的内联CSS样式(<div s ...

  10. eigen 笔记1

    c++ 的 eigen 类似于 python 的 numpy, 还有一个类似的库是 Armadillo, 当然还有 opencv. Armadillo 与 matlab 在函数名称上更接近, 但是 T ...