题目链接:

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. HTTP.SYS远程代码执行漏洞测试(ms15-034)

    1.HTTP.SYS远程代码执行漏洞简介 首先漏洞编号:CVE-2015-1635(MS15-034 ) 远程执行代码漏洞存在于 HTTP 协议堆栈 (HTTP.sys) 中,当 HTTP.sys 未 ...

  2. my18_mysql中的几个超时时间

    连接的超时时间 set global interactive_timeout=120;set global wait_timeout=120; 该连接指类似应用访问数据库的连接,可以是查询.DML.D ...

  3. php程序设计 1,2章节

    <?php/** * Created by PhpStorm. * User: DY040 * Date: 2017/9/4 * Time: 10:39 * * * 1: php起源于1995 ...

  4. UGUI Slider

    1.新建一个Cube命名为Player,在上面挂一个脚本命名为Player,脚本内容如下: using System.Collections; using System.Collections.Gen ...

  5. Magnum DevStack安装

    local.conf文件 [[local|localrc]]DATABASE_PASSWORD=123456RABBIT_PASSWORD=123456SERVICE_TOKEN=123456SERV ...

  6. typescript的lambads解决this关键字找不到属性

    var people = { name: ["abc", "jack", "pepter", "jim"], getna ...

  7. css内容整理2

    10.6.css伪类.伪元素 伪类用于向某些选择器添加特殊效果:伪元素用于将特殊的效果添加达到某选择器. 区别:伪类的效果可通过添加一个实际的类达到,用::伪元素效果则需要添加一个实际的元素,用:: ...

  8. [Java][Servlet] Cannot call sendRedirect() after the response has been committed

    做一个Login Demo的时候,写了如下代码: protected void doPost(HttpServletRequest request, HttpServletResponse respo ...

  9. JDBC之Java连接mysql实现增删改查

    使用软件:mysql.eclipse 链接步骤: 1.注册驱动 2.创建一个连接对象 3.写sql语句 4.执行sql语句并返回一个结果或者结果集 5.关闭链接(一般就是connection.stat ...

  10. Net-SNMP(V3协议)安装配置笔记(CentOS 5.2)(转)

    原出处:http://blog.ihipop.info/2010/03/722.html 为了这颗仙人掌(cacti),我必须先部署(Net-SNMP), 同时我为了安全因素,也为了简便考虑,决定采用 ...