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直接算出来就是某点的值,怎么做到的呢? 我们在更新的时候不止更新一个点,而是 ...
随机推荐
- elasticsearch数据转移,elasticdump的安装使用
模拟: 将本地的my_index的products的一条document转移到http://192.168.111.130的一个es服务器上. (一)安装elasticdump 先安装node.js, ...
- libevent 网络IO分析
libevent 网络IO分析 Table of Contents 1. 简介 2. 简单使用与入门 2.1. 定时器-timeout 超时回调 2.2. 信号事件 2.3. 读取 socket 3. ...
- 前端(以Vue为例)webpack打包后dist文件包如何部署到django后台中
由于现在前端使用的三大框架配合webpack可以实现快速打包,为部署到服务端提供了非常大的便利,那么在前端打包后,应该做些什么可以部署到django的后台中呢? 1.打包后文件包dist 进入到 di ...
- java NIO (二) 一个故事讲清楚NIO
假设某银行只有10个职员.该银行的业务流程分为以下4个步骤: 1) 顾客填申请表(5分钟): 2) 职员审核(1分钟): 3) 职员叫保安去金库取钱(3分钟): 4) 职员打印票据,并将钱和票据返回给 ...
- android switch控件
<Switch android:layout_width="wrap_content" android:layout_height="@dimen/minCellH ...
- 总结)Nginx/LVS/HAProxy负载均衡软件的优缺点详解
总结)Nginx/LVS/HAProxy负载均衡软件的优缺点详解 PS:Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,参考了一些资料,结合自己的一些使 ...
- mysql查看和修改注释
MySQL查看注释,MySQL修改注释,mysql查看注释,mysql修改注释 1.给大家做演示,这里随便创建一张学生表,代码如下: CREATE TABLE `student` ( `id` int ...
- 【Flask】关于Flask的request属性
前言 在进行Flask开发中,前端需要发送不同的请求及各种带参数的方式,比如GET方法在URL后面带参数和POST在BODY带参数,有时候又是POST的表单提交方式,这个时候就需要从request提取 ...
- [LeetCode] 133. Clone Graph_ Medium tag: BFS, DFS
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...
- [LeetCode] 237. Delete Node in a Linked List_Easy tag: Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...