题目链接:

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. 读书印记 - 《文革前的邓小平:毛XX的副帅》

    开始看才发现这居然是本学术著作,阅读难度系数比小说.传记要很多,相比于小说的人物心理.传记的故事套路,这本书的基本写法是举一大坨材料来描述当时的事实然后稍微发表一点学术观点.....我对这个内容本身挺 ...

  2. robotframe 学习笔记1

    在robot framework中,通过 Set variable关键字来定义变量 连接对象: 通过Catenate关键字可以连接多个信息 加上"SEPARATOR=",可以对多个 ...

  3. Python APIs

    NDArray API Python API速查

  4. MAYA删除不干净

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  5. Murano Weekly Meeting 2015.09.15

    Meeting time: 2015.September.15th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting s ...

  6. Sublime_text 3 安装 Package Control

    作者博文地址:https://www.cnblogs.com/liu-shuai/ 一.自动安装: 1.通过快捷键 ctrl+` 或者 View > Show Console 菜单打开控制台 2 ...

  7. Map集合练习之对字符串中字母出现的次数求和

    不多说,直接上干货! 代码需求 如有这么一个字符串 String str = "fdg+avAdc bs5dDa9c-dfs"; MapTest.java package zhou ...

  8. PHP编码的规范性

         为了提高工作效率,保证开发的有效性和合理性,并最大程度提高程序代码的可读性和可重复利用性,提高沟通效率,需要一份代码编辑规范.         一.文件标记:            1.所有 ...

  9. Andrew Ng 的 Machine Learning 课程学习 (week3) Logistic Regression

    这学期一直在跟进 Coursera上的 Machina Learning 公开课, 老师Andrew Ng是coursera的创始人之一,Machine Learning方面的大牛.这门课程对想要了解 ...

  10. Tomcat实现Session共享

    一个Tomcat中有多一个web应用,然后想共享session,只需在host中加上 <Valve className="org.apache.catalina.authenticat ...