poj2029 Get Many Persimmon Trees
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';
}
}
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 4649 | Accepted: 3025 |
Description
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
N
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
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的更多相关文章
- POJ2029——Get Many Persimmon Trees
Get Many Persimmon Trees Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3656 Accepte ...
- POJ-2029 Get Many Persimmon Trees(动态规划)
Get Many Persimmon Trees Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3987 Accepted: 2 ...
- POJ2029:Get Many Persimmon Trees(二维树状数组)
Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...
- POJ 2029 Get Many Persimmon Trees
Get Many Persimmon Trees Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3243 Accepted: 2 ...
- (简单) POJ 2029 Get Many Persimmon Trees,暴力。
Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...
- POJ 2029 Get Many Persimmon Trees (二维树状数组)
Get Many Persimmon Trees Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I ...
- xtu数据结构 B. Get Many Persimmon Trees
B. Get Many Persimmon Trees Time Limit: 1000ms Memory Limit: 30000KB 64-bit integer IO format: %lld ...
- POJ-2029 Get Many Persimmon Trees---二维树状数组+枚举
题目链接: https://vjudge.net/problem/POJ-2029 题目大意: 有N棵树在一个n*m的田里,给出每颗树的坐标 用一个s*t的矩形去围,最多能围几棵树 思路: 用二维树状 ...
- POJ 2029 Get Many Persimmon Trees(DP||二维树状数组)
题目链接 题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树.输出数目 思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做. #include <stdio ...
随机推荐
- [Lugu3380]【模板】二逼平衡树(树套树)
题面戳我 您需要写一种数据结构来维护一个有序数列,其中需要提供以下操作: 1.查询k在区间内的排名 2.查询区间内排名为k的值 3.修改某一位值上的数值 4.查询k在区间内的前驱(前驱定义为严格小于x ...
- docker 一键安装zabbix server、zabbix agent
基本原理.须知:1.zabbix 分为zabbix server和zabbix agent,其中zabbix server需要web环境,并且其数据存储在独立的数据库中:2.docker是一种容器服务 ...
- Listener监听器生命周期
一.Listener生命周期 listener是web三大组件之一,是servlet监听器,用来监听请求,监听服务端的操作. listener分为:(都是接口类,必须实现相应方法) 1.生命周期监听器 ...
- centos6.5下 hdp-2.4.2安装
(1)准备工作 /usr/sbin/sestatus -v getenforce1./usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态SE ...
- c#多线程同步之EventWaitHandle再次使用
/// <summary> /// 文件传输器,用来获取全文文件,自动根据全文文件数量,开启一定数量的线程,采用生产者消费模式 /// </summary> public cl ...
- Java Swing应用程序JLable超链接
在HTML中设置一个超链接是很容易的,使用<a></a>标签就可以完成了. 在客户端应用程序中,并没有这样的标签,但是可以使用按钮来实现,But 有时候就是想好看一点,不想要按 ...
- vue.js 配置移动端的url Scheme和iOS端配置url Scheme
假如urlScheme:baibai:// 一.vue.js端的配置: 1.通过html标签跳转: <p href="baibai://"></p> 2.通 ...
- 关于“应用程序无法启动,因为应用程序的并行配置不正确。请参阅应用程序事件日志,或使用命令行sxstrace.exe工具”问题的解决方法
今天打开QQ管家加速版的时候突然出现了这个错误,百度了下说是系统缺少Microsoft Visual C++ 20XX(运行库),下载这个安装即可解决问题.
- 优先级队列用法详解(priority_queue)
由于优先级队列的内部数据结构为 堆,所以这里先介绍堆的一些操作. 堆的一些函数操作在algorithm头文件中 //在[first, last)范围内构造最大堆,first,last 可以是vecto ...
- FNV算法实战
HASH算法介绍 Hash,一般翻译做"散列",也有直接音译为"哈希"的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长 ...