<题目链接>

题目大意:

给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点。

解题分析:
二维树状数组模板题。

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int M =+;
int tr[M][M];
int n,W,H,w,h;
int lowbit(int x){return x&(-x);}
void add(int x,int y,int val){
for(int i = x;i <= H;i += lowbit(i)){
for(int j = y;j <= W;j += lowbit(j)){
tr[i][j] += val;
}
}
}
int sum(int x,int y){
int ans = ;
for(int i = x;i > ;i -= lowbit(i)){
for(int j = y;j > ;j -= lowbit(j)){
ans += tr[i][j];
}
}
return ans;
}
int main(){
while(scanf("%d",&n)!=EOF,n){
memset(tr,,sizeof(tr));
scanf("%d%d",&H,&W);
for(int i=;i<=n;i++){
int x,y;
scanf("%d%d",&x,&y);
add(x,y,);
}
scanf("%d%d",&h,&w);
int ans=-;
for(int i=h;i<=H;i++){
for(int j=w;j<=W;j++){
int res=sum(i,j)-sum(i-h,j)-sum(i,j-w)+sum(i-h,j-w); //sum(x,y)代表(1,1)到(x,y)这个矩阵包含多少个点
ans=max(ans,res);
}
}
printf("%d\n",ans);
}
return ;
}

2018-10-17

POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】的更多相关文章

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

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

  2. 模板:二维树状数组 【洛谷P4054】 [JSOI2009]计数问题

    P4054 [JSOI2009]计数问题 题目描述 一个n*m的方格,初始时每个格子有一个整数权值.接下来每次有2种操作: 改变一个格子的权值: 求一个子矩阵中某种特定权值出现的个数. 输入输出格式 ...

  3. BZOJ 1452 Count 【模板】二维树状数组

    对每种颜色开一个二维树状数组 #include<cstdio> #include<algorithm> using namespace std; ; ][maxn][maxn] ...

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

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

  5. POJ2029:Get Many Persimmon Trees(二维树状数组)

    Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...

  6. POJ 2155 Matrix 【二维树状数组】(二维单点查询经典题)

    <题目链接> 题目大意: 给出一个初始值全为0的矩阵,对其进行两个操作. 1.给出一个子矩阵的左上角和右上角坐标,这两个坐标所代表的矩阵内0变成1,1变成0. 2.查询某个坐标的点的值. ...

  7. hdu 2642二维树状数组 单点更新区间查询 模板题

    二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...

  8. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  9. Get Many Persimmon Trees_枚举&&二维树状数组

    Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...

随机推荐

  1. Confluence 6 导入模板的步骤

    第一步:检查你 Confluence 站点中安装的模板组件 查看当前已经导入到你 Confluence 站点中可用的模板组件: 以系统管理员或者 Confluence 管理员权限登录 Confluen ...

  2. 开源中国社区 https://git.oschina.net/ 添加 SSH 公钥 添加

    首先可以参考官方的帮助文档 http://git.mydoc.io/?t=154712 然后进去码云首页 http://git.oschina.net 然后找到右边的头像点击一下  然后点击修改资料 ...

  3. python并发编程之多线程1

    一多线程的概念介绍 threading模块介绍 threading模块和multiprocessing模块在使用层面,有很大的相似性. 二.开启多线程的两种方式 1.创建线程的开销比创建进程的开销小, ...

  4. Java并发编程-并发工具类及线程池

    JUC中提供了几个比较常用的并发工具类,比如CountDownLatch.CyclicBarrier.Semaphore. CountDownLatch: countdownlatch是一个同步工具类 ...

  5. laravel 更新验证

    public function update(Request $request, User $user) { // 验证规则. $rules = [ 'email' => [ 'nullable ...

  6. 小学生都看得懂的C语言入门(1): 基础/判别/循环

    c基础入门, 小学生也可以都看得懂!!!! 安装一个编译器, 这方面我不太懂, 安装了DEV-C++  ,体积不大,30M左右吧, 感觉挺好用,初学者够了. 介绍下DEV 的快键键: 恢复 Ctrl+ ...

  7. poj2441状态压缩dp基础

    /* 给定n头牛,m个谷仓,每头牛只能在一些特定的谷仓,一个谷仓只能有一头牛 问可行的安排方式 dp[i][j]表示前i头牛组成状态j的方案数,状态0表示无牛,1表示有牛 使用滚动数组即可 枚举到第i ...

  8. python DLL接口测试

    #coding=utf-8 import clr import sys import threading from itertools import permutations sys.path.app ...

  9. 对象存储服务(Object Storage Service,简称 OSS)

    阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量.安全.低成本.高可靠的云存储服务.它具有与平台无关的RESTful API接口,能够提供99.99 ...

  10. 解决notepad++64位没有plugin manager的问题

    安装了最新的notepad++版本发现没有插件管理器,很难受. 后来上官网发现了这样一句话 Note that the most of plugins (including Plugin Manage ...