POJ 2029 (二维树状数组)题解
思路:
大力出奇迹,先用二维树状数组存,然后暴力枚举
算某个矩形区域的值的示意图如下,代码在下面慢慢找...
代码:
#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 (二维树状数组)题解的更多相关文章
- poj 2029 二维树状数组
思路:简单树状数组 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...
- POJ 1195 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18489 Accepted: 8558 De ...
- poj 3378 二维树状数组
思路:直接用long long 保存会WA.用下高精度加法就行了. #include<map> #include<set> #include<cmath> #inc ...
- poj 2155 (二维树状数组 区间修改 求某点值)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 33682 Accepted: 12194 Descript ...
- Mobile phones POJ - 1195 二维树状数组求和
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...
- POJ 2029 Get Many Persimmon Trees (二维树状数组)
Get Many Persimmon Trees Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I ...
- POJ 2029 Get Many Persimmon Trees(DP||二维树状数组)
题目链接 题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树.输出数目 思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做. #include <stdio ...
- POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】
<题目链接> 题目大意: 给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点. 解题分析:二维树状数组模板题. #include <cstdio ...
- POJ 2155 Matrix (二维树状数组)题解
思路: 没想到二维树状数组和一维的比只差了一行,update单点更新,query求和 这里的函数用法和平时不一样,query直接算出来就是某点的值,怎么做到的呢? 我们在更新的时候不止更新一个点,而是 ...
随机推荐
- Prime Path--POJ3126(bfs)
Description The ministers of the cabinet were quite upset by the message from the Chief of Security ...
- 【爬坑】python3+pyqt5+pyinstaller 打包成exe的各种问题
windows系统+python3+pyqt5+pyinstaller打包,经常会出现各种打包异常情况.如果代码没有特别异常,那么综合原因,大抵都是这四个元素之间的匹配问题,引起的.作者:一心狮链接: ...
- linux删除指定行&删除行首空格&替换字符
打印并删除2~1000行 nl /etc/passwd | sed '2,1000d' |more 删除行首空格 sed -i 's/^[][ ]*//g' file 替换分隔符 说明:文件中数据是由 ...
- csv文件的读写
# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. "&quo ...
- 非受限联合体 - 现代C++新特性总结
非受限联合体 非受限联合体:C++98中并不是所有数据类型都能够成为union的数据成员,不允许联合体拥有非POD(Plain Old Data).静态或引用类型的成员. C++11中取消了联合体对于 ...
- windows使用方法
1:截图搜索英文单词:snipping tool 2: 修改语言,搜索language 3:关闭fn键,按键 fn+esc(fnlock). 就可以将fn关闭和开启.
- [vue]vue-book
我们打算要做这几个模块 首页 列表 收藏 添加 home.vue --> list.vue -->app.vue --> main.js 安装环境 npm i vue-cli -g ...
- ComBSTR的使用
用 CComBSTR 进行编程 Visual Studio .NET 2003 3(共 3)对本文的评价是有帮助 - 评价此主题 ATL 类 CComBSTR 提供对 BSTR 数据类型的包装 ...
- Summary: 书架问题
Consider the problem of storing n books on shelves in a library. The order of the books is fixed by ...
- QLabel 文本内容自动换行显示
需要把QLabel的WordWrap属性设置成TRUE,可以通过界面设置,也可以通过程序设置