问一个矩形框在一个大矩形内最多能围几个给定的点

都不用排序,先把所有的点加入树状数组,再直接枚举大矩形的每个格子即可

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <list>
#include <algorithm>
#include <climits>
using namespace std; #define lson 2*i
#define rson 2*i+1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 1005
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define lowbit(x) (x&-x)
const int mod = 1e9+; int c[N][N],n,m,cnt,s,t; int sum(int x,int y)
{
int ret = ;
int i,j;
for(i = x;i>=;i-=lowbit(i))
{
for(j = y;j>=;j-=lowbit(j))
{
ret+=c[i][j];
}
}
return ret;
} void add(int x,int y,int d)
{
int i,j;
for(i = x;i<=n;i+=lowbit(i))
{
for(j = y;j<=m;j+=lowbit(j))
{
c[i][j]+=d;
}
}
} int main()
{
int i,j,x,y,ans;
while(~scanf("%d",&cnt),cnt)
{
ans = ;
scanf("%d%d",&n,&m);
MEM(c,);
for(i = ;i<=cnt;i++)
{
scanf("%d%d",&x,&y);
add(x,y,);
}
scanf("%d%d",&s,&t);
for(i = ;i<=n;i++)
{
for(j = ;j<=m;j++)
{
int x1 = i,y1 = j,x2 = x1+s-,y2 = y1+t-;
if(x2>n || y2>m) continue;
int s = sum(x2,y2)+sum(x1-,y1-)-sum(x2,y1-)-sum(x1-,y2);
ans = max(ans,s);
}
}
printf("%d\n",ans);
} return ;
}

zoj1716简单的二维树状数组的更多相关文章

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

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

  2. (简单) POJ 1195 Mobile phones,二维树状数组。

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  3. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  4. [POJ2155]Matrix(二维树状数组)

    题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...

  5. 二维树状数组——SuperBrother打鼹鼠(Vijos1512)

    树状数组(BIT)是一个查询和修改复杂度都为log(n)的数据结构,主要用于查询任意两位之间的所有元素之和,其编程简单,很容易被实现.而且可以很容易地扩展到二维.让我们来看一道很裸的二维树状数组题: ...

  6. 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)

    BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...

  7. PKU 2155 Matrix(裸二维树状数组)

    题目大意:原题链接 题意很简单,就不赘诉了. 解题思路: 使用二维树状数组,很裸的题. 二维的写起来也很方便,两重循环. Add(int x,int y,int val)表示(x,y)-(n,n)矩形 ...

  8. BZOJ3132 上帝造题的七分钟 【二维树状数组】

    题目 "第一分钟,X说,要有矩阵,于是便有了一个里面写满了0的n×m矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为(a,b),右下角为(c,d)的一个矩形区域内的全部数字加上一个值的 ...

  9. [bzoj3132]上帝造题的七分钟——二维树状数组

    题目大意 你需要实现一种数据结构,支援以下操作. 给一个矩阵的子矩阵的所有元素同时加一个数. 计算子矩阵和. 题解 一看这个题,我就首先想到用线段树套线段树做. 使用二维线段树的错误解法 其实是第一次 ...

随机推荐

  1. (转)Go中的string和[]byte对比

    本文转自:https://sheepbao.github.io/post/golang_byte_slice_and_string/ 作者:boya 声明:本文目的仅仅作为个人mark,所以在翻译的过 ...

  2. Tomcat的配置文件详解

    Tomcat的配置文件详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Tomcat的配置文件 Tomcat的配置文件默认存放在$CATALINA_HOME/conf目录中, ...

  3. Python基础【day03】:字典(一)

    本节内容 简述 语法 字典的使用 字典内置方法 一.简述 字典是Python中的又一种数据结构,它是通过key-value的数据类型,跟我们小时候用的新华字典差不多,通过key去访问value 二.语 ...

  4. springSession框架来实现sso单点登陆

    介绍一下springsession这个框架,其实springsession框架默认的是使用redis来实现单点登陆的,但是不支持redis集群,这个框架的特点是无侵入的实现单点登陆,就是说我们之前获取 ...

  5. HDU - 5419 Victor and Toys(组合计数)

    http://acm.hdu.edu.cn/showproblem.php?pid=5419 题意 n个物品,标号1-n,物品i有权值wi.现在有m个区间[l,r],从中任意选三个区间i,j,k,求物 ...

  6. C++ STL sort()函数用法

    C++STL提供的在里的排序函数,有以下两种形式 此外还提供有稳定排序版本stable_sort(),用法类似. 第一种形式: template <class RandomAccessItera ...

  7. DotNetBar 控件设置空内容时显示内容

    可以通过修改所有关于Watermark时的设置.

  8. 发现一sonar-runner bug

    最近在使用sonar-runner做代码扫描, 在windows环境运行多模块的扫描ok,但是在linux上sonar-runner扫描多模块报错: 先贴sonar-project.propertie ...

  9. MySQL中查询行数最多的表并且排序

    #切换到schema use information_schema; #查询数据量最大的30张表 并排序 select table_name,table_rows from tables order ...

  10. F - Set of Strings

    You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concat ...