题目链接:

https://vjudge.net/problem/POJ-2029

题目大意:

有N棵树在一个n*m的田里,给出每颗树的坐标

用一个s*t的矩形去围,最多能围几棵树
思路:
用二维树状数组求区域和,也可以直接用二维前缀和求解
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#define lowbot(i) (i&(-i))
using namespace std;
typedef long long ll;
const int maxn = + ;
int n, m, T, k, cases;
int tree[maxn][maxn];
void add(int x, int y, int d)
{
for(int i = x; i <= n; i += lowbot(i))
{
for(int j = y; j <= m; j += lowbot(j))
{
tree[i][j] += d;
}
}
}
int sum(int x, int y)
{
int ans = ;
for(int i = x; i > ; i -= lowbot(i))
{
for(int j = y; j > ; j -= lowbot(j))
{
ans += tree[i][j];
}
}
return ans;
}
int Sum(int x1, int y1, int x2, int y2)
{
return sum(x2, y2) + sum(x1 - , y1 - ) - sum(x1 - , y2) - sum(x2, y1 - );
}
int main()
{
while(cin >> k && k)
{
int x, y, s, t;
memset(tree, , sizeof(tree));
cin >> n >> m;
while(k--)
{
scanf("%d%d", &x, &y);
add(x, y, );
}
cin >> s >> t;
int ans = ;
for(int i = ; i + s - <= n; i++)
{
for(int j = ; j + t - <= m; j++)
{
int tot = Sum(i, j, i + s - , j + t - );
ans = max(ans, tot);
}
}
cout<<ans<<endl;
}
return ;
}

POJ-2029 Get Many Persimmon Trees---二维树状数组+枚举的更多相关文章

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

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

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

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

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

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

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

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

  5. POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】

    <题目链接> 题目大意: 给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点. 解题分析:二维树状数组模板题. #include <cstdio ...

  6. POJ 2029 (二维树状数组)题解

    思路: 大力出奇迹,先用二维树状数组存,然后暴力枚举 算某个矩形区域的值的示意图如下,代码在下面慢慢找... 代码: #include<cstdio> #include<map> ...

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

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

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

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

  9. POJ 2155 Matrix【二维树状数组+YY(区间计数)】

    题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  10. POJ 2155 Matrix(二维树状数组,绝对具体)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20599   Accepted: 7673 Descripti ...

随机推荐

  1. Java的Protected

    没想到接触Java这么多年,今天竟然才发现一直有一个误解 Proteced只能被同一个包内的或者子类的class访问 那么在另一个包的如下代码有问题吗? Sub sub = new Sub(); su ...

  2. 隐藏win10中“此电脑”里的6个子文件夹

    删除点击此电脑后6个子文件夹 运行regedit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Fold ...

  3. WEB视频播放器插件,总结

    WEB视频播放器插件,总结 2018年07月29日 20:42:11 流光忆莲 阅读数:572更多 个人分类: 推荐文章收藏   以下是关于网页中嵌入视频播放插件的各种资料的总结 基于H5的Vedio ...

  4. 使用Ext 创建树

    ext使用的是ext3.4.0版本 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> < ...

  5. python_案例综合:教材记录管理

    class Book(): def __init__(self,ISBN,Ftile,Author,Publisher): self.ISBN = ISBN self.Ftile = Ftile se ...

  6. python 进程池Pool以及Queue的用法

    import os,time,random from multiprocessing import Pool def task(name): print('正在运行的任务:%s,PID:(%s)'%( ...

  7. hybird app 工具选型

    目前hybird app工具众多,如何选择?哪个坑少点呢? 下面来分析一下: 1开发工具都开源.基于Eclipse的有:apicloud,WeX5 2热门指数.下面的百度的搜索结果数,代表不了什么,至 ...

  8. JEECMS站群管理系统-- Jeecms项目导入myeclipse

    1.在myeclipse中新建一个项目jeecms,将服务器中jeecms项目下web-inf文件夹下内容拷到新建项目中 解压缩jeecms-3.0.2-final-src,在src文件夹下会看到有三 ...

  9. http 中的缓存

    如何判断缓存新鲜度 If-Modified-Since告诉服务器, 在服务器中的响应报文中有一个Last-Modified字段, 如果两者一直则表示在浏览器中缓存的文件是最新的, 可以直接使用浏览器缓 ...

  10. c++隐式类型转换和explicit

    什么是隐式转换? 众所周知,C++的基本类型中并非完全的对立,部分数据类型之间是可以进行隐式转换的. 所谓隐式转换,是指不需要用户干预,编译器私下进行的类型转换行为.很多时候用户可能都不知道进行了哪些 ...