http://poj.org/problem?id=2029

单点修改

矩阵查询

二维线段树

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> using namespace std; int w,h;
int x,y;
int xl,yl,xr,yr; #define N 101 int sum[N<<][N<<]; int cnt; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} void changey(int kx,int ky,int l,int r)
{
if(l==r)
{
sum[kx][ky]++;
return;
}
int mid=l+r>>;
if(y<=mid) changey(kx,ky<<,l,mid);
else changey(kx,ky<<|,mid+,r);
sum[kx][ky]=sum[kx][ky<<]+sum[kx][ky<<|];
} void changex(int kx,int l,int r)
{
changey(kx,,,h);
if(l==r) return;
int mid=l+r>>;
if(x<=mid) changex(kx<<,l,mid);
else changex(kx<<|,mid+,r);
} void queryy(int kx,int ky,int l,int r)
{
if(l>=yl && r<=yr)
{
cnt+=sum[kx][ky];
return;
}
int mid=l+r>>;
if(yl<=mid) queryy(kx,ky<<,l,mid);
if(yr>mid) queryy(kx,ky<<|,mid+,r);
} void queryx(int kx,int l,int r)
{
if(l>=xl && r<=xr)
{
queryy(kx,,,h);
return;
}
int mid=l+r>>;
if(xl<=mid) queryx(kx<<,l,mid);
if(xr>mid) queryx(kx<<|,mid+,r);
} int main()
{
int n,s,t;
int ans;
while(scanf("%d",&n)!=EOF)
{
if(!n) return ;
memset(sum,,sizeof(sum));
read(w); read(h);
while(n--)
{
read(x); read(y);
changex(,,w);
}
read(s); read(t);
ans=;
for(int j=t;j<=h;++j)
for(int i=s;i<=w;++i)
{
xl=i-s+;
yl=j-t+;
xr=i;
yr=j;
cnt=;
queryx(,,w);
ans=max(ans,cnt);
}
cout<<ans<<'\n';
}
}
Get Many Persimmon Trees
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 4649   Accepted: 3025

Description

Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate was strictly specified by the lord, he was allowed to choose any location for the estate in the field. Inside the field which had also a rectangular shape, many Japanese persimmon trees, whose fruit was one of the famous products of the Aizu region known as 'Mishirazu Persimmon', were planted. Since persimmon was Hayashi's favorite fruit, he wanted to have as many persimmon trees as possible in the estate given by the lord. 
For example, in Figure 1, the entire field is a rectangular grid whose width and height are 10 and 8 respectively. Each asterisk (*) represents a place of a persimmon tree. If the specified width and height of the estate are 4 and 3 respectively, the area surrounded by the solid line contains the most persimmon trees. Similarly, if the estate's width is 6 and its height is 4, the area surrounded by the dashed line has the most, and if the estate's width and height are 3 and 4 respectively, the area surrounded by the dotted line contains the most persimmon trees. Note that the width and height cannot be swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure 1. 
 
Figure 1: Examples of Rectangular Estates
Your task is to find the estate of a given size (width and height) that contains the largest number of persimmon trees.

Input

The input consists of multiple data sets. Each data set is given in the following format.


W H 
x1 y1 
x2 y2 
... 
xN yN 
S T

N is the number of persimmon trees, which is a positive integer less than 500. W and H are the width and the height of the entire field respectively. You can assume that both W and H are positive integers whose values are less than 100. For each i (1 <= i <= N), xi and yi are coordinates of the i-th persimmon tree in the grid. Note that the origin of each coordinate is 1. You can assume that 1 <= xi <= W and 1 <= yi <= H, and no two trees have the same positions. But you should not assume that the persimmon trees are sorted in some order according to their positions. Lastly, S and T are positive integers of the width and height respectively of the estate given by the lord. You can also assume that 1 <= S <= W and 1 <= T <= H.

The end of the input is indicated by a line that solely contains a zero.

Output

For each data set, you are requested to print one line containing the maximum possible number of persimmon trees that can be included in an estate of the given size.

Sample Input

16
10 8
2 2
2 5
2 7
3 3
3 8
4 2
4 5
4 8
6 4
6 7
7 5
7 8
8 1
8 4
9 6
10 3
4 3
8
6 4
1 2
2 1
2 4
3 4
4 2
5 3
6 1
6 2
3 2
0

Sample Output

4
3

poj2029 Get Many Persimmon Trees的更多相关文章

  1. POJ2029——Get Many Persimmon Trees

    Get Many Persimmon Trees Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3656   Accepte ...

  2. POJ-2029 Get Many Persimmon Trees(动态规划)

    Get Many Persimmon Trees Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3987 Accepted: 2 ...

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

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

  4. POJ 2029 Get Many Persimmon Trees

    Get Many Persimmon Trees Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3243 Accepted: 2 ...

  5. (简单) POJ 2029 Get Many Persimmon Trees,暴力。

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

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

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

  7. xtu数据结构 B. Get Many Persimmon Trees

    B. Get Many Persimmon Trees Time Limit: 1000ms Memory Limit: 30000KB 64-bit integer IO format: %lld  ...

  8. POJ-2029 Get Many Persimmon Trees---二维树状数组+枚举

    题目链接: https://vjudge.net/problem/POJ-2029 题目大意: 有N棵树在一个n*m的田里,给出每颗树的坐标 用一个s*t的矩形去围,最多能围几棵树 思路: 用二维树状 ...

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

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

随机推荐

  1. 【SPOJ】Distinct Substrings(后缀自动机)

    [SPOJ]Distinct Substrings(后缀自动机) 题面 Vjudge 题意:求一个串的不同子串的数量 题解 对于这个串构建后缀自动机之后 我们知道每个串出现的次数就是\(right/e ...

  2. NOIP2017划水记

    考完好久后才想起来写个总结 Day0 在Luogu上码了几道模板题 然后就忍不住和机房的人开始颓了本来说要复习一下的 将军棋到CS,一直在颓CS打的还不错 晚上开了几把后就昏昏沉沉睡了 Day1 好紧 ...

  3. C# Redis实战(六)

    六.查询数据 在C# Redis实战(五)中介绍了如何删除Redis中数据,本篇将继续介绍Redis中查询的写法. 1.使用Linq匹配关键字查询 using (var redisClient = R ...

  4. RHEL7 网卡绑定

     //bond(主要用于6系统) nmcli connection add type bond mode balance-rr con-name bond0 ifname bond0 ipv4.met ...

  5. 解决JSON.stringify()自动将中文转译成unicode的方法

    最近在工作中,发现在IE8下JSON.stringify()自动将中文转译为unicode编码,原本选择的中文字符,传到后台变为了unicode编码,即\u****的形式.查找资料后发现,与标准的JS ...

  6. 开启第一个Node.js的Express项目

    手动创建一个Express.js的应用可大致分为以下步骤: 1.创建文件夹 a. 创建一个项目根文件夹,如helloWord b.在项目的根目录下创建项目的目录结构,依次创建{public,publi ...

  7. nginx location匹配顺序及CI框架的nginx配置

    Nginx location匹配顺序如下: 用前缀字符串定义的location规则对URI进行匹配测试. =号定义了精确的前缀字符串匹配,如果发现精确匹配则使用当前规则.否则继续下一步匹配. 匹配其它 ...

  8. MongoDB入门系列:复制机制

    一.复制原理 MongoDB的复制功能是使用操作日志oplog实现的,oplog包含主节点(Master)的每一次写操作,oplog是local本地数据库中的一个数据集合,其它非主节点(Seconda ...

  9. numpy pandas 索引注意事项

    pandas.DataFrame 的 iloc # ------------------------------------------------------------ 'python式的切片,包 ...

  10. Could not create the view: An unexpected exception was thrown的解决方法

    MyEclipse下面的server窗口突然不能正常显示了,而且还显示Could not create the view: An unexpected exception was thrown(无法创 ...