<题目链接>

题目大意:

给你一个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. LoadRunner监控window系统各项指标详解

    一.监控系统时,需要监控的项 System 系统 Processor 处理器 Memory 内存 PhysicalDisk 磁盘 Server 服务器 二.指标详解 (一). PhysicalDisk ...

  2. LeetCode(71):简化路径

    Medium! 题目描述: 给定一个文档 (Unix-style) 的完全路径,请进行路径简化. 例如,path = "/home/", => "/home&quo ...

  3. bzoj2973转移矩阵构造法!

    /* 构造单位矩阵(转移矩阵) 给定n*m网格,每个格子独立按照长度不超过6的操作串循环操作 对应的操作有 0-9:拿x个石头到这个格子 nwse:把这个格子的石头推移到相邻格子 d:清空该格石子 开 ...

  4. 步步为营-74-Request,Response和server的其他成员

    Request 1 Request.UrlReferrer 获取请求的来源 2 Request.UserHostAddress 获取访问者的IP地址 3 Request.Cookies 获取浏览器发送 ...

  5. 目标检测算法之R-CNN算法详解

    R-CNN全称为Region-CNN,它可以说是第一个成功地将深度学习应用到目标检测上的算法.后面提到的Fast R-CNN.Faster R-CNN全部都是建立在R-CNN的基础上的. 传统目标检测 ...

  6. python 内建函数

    # # __geratteibute__class Itcast(object): def __init__(self,subject1): self.subject1 = subject1 self ...

  7. css解决td单元格内文字溢出

    <table>标签加样式:table-layout:fixed;(一定要加,否则下面定义的td的样式都不起作用了) <td>加样式:overflow:hidden;text-o ...

  8. Tomcat使用https

    # 用JDK自带的Keytool生成keystore文件keytool -genkey -alias tomcat -keyalg RSA -keypass Envisi0n -storepass E ...

  9. 微信支付JSAPI掉不起来支付按钮是什么原因?(原创)

    两种可能: 1.支付页面的js参数有问题 2.微信支付的配置有问题,大概率在微信支付授权目录是否有填写正确

  10. mysql binary

    mysql在比较字符串的时候是忽略大些写的 比如有用户叫ABC和abc select * from `sys_user` where username = 'abc' 会出来两条记录 select * ...