思路:

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

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

代码:

#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. 单例模式:Qt本身就提供了专门的宏 Q_GLOBAL_STATIC 通过这个宏不但定义简单,还可以获得线程安全性

    标题起的是有点大 主要是工作和学习中,遇到些朋友,怎么说呢,代码不够Qt化 可能是由于他们一开始接触的是 Java MFC 吧 接触 Qt 7个年头了 希望我的系列文章能抛砖引玉吧 单例模式 很多人洋 ...

  2. 洛谷P3389 高斯消元 / 高斯消元+线性基学习笔记

    高斯消元 其实开始只是想搞下线性基,,,后来发现线性基和高斯消元的关系挺密切就一块儿在这儿写了好了QwQ 先港高斯消元趴? 这个算法并不难理解啊?就会矩阵运算就过去了鸭,,, 算了都专门为此写个题解还 ...

  3. libevent 网络IO分析

    libevent 网络IO分析 Table of Contents 1. 简介 2. 简单使用与入门 2.1. 定时器-timeout 超时回调 2.2. 信号事件 2.3. 读取 socket 3. ...

  4. WebDriver 常用操作

    1 浏览器操作 2 窗口和弹框操作 3 cookies 操作 4 简单对象的定位 5 页面元素操作 6 鼠标事件 7 键盘事件 1 浏览器操作 #属性: driver.current_url #用于获 ...

  5. 006-Redis 发布订阅

    Redis 发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息. Redis 客户端可以订阅任意数量的频道. 下图展示了频道 channel1 , 以及订 ...

  6. HTML5插件

    HTML 助手(插件) 辅助应用程序(helper application)是可由浏览器启动的程序.辅助应用程序也称为插件. 辅助程序可用于播放音频和视频(以及其他).辅助程序是使用 <obje ...

  7. isScroll的滚动组件的用法

    <div class="wrapper">  <ul>     <li>1</li>     <li>2</li& ...

  8. [py]django前台处理后端返回的各类数据

    参考 要完成的任务 返回str 返回list 返回arr 前端遍历 关键字 if for语句处理str list dict - 遍历字典 for语句 {% for key, value in info ...

  9. PAT 1023 Have Fun with Numbers[大数乘法][一般]

    1023 Have Fun with Numbers (20)(20 分) Notice that the number 123456789 is a 9-digit number consistin ...

  10. PAT Spell It Right [非常简单]

    1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...