题目链接:

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. Jenkins自动化CI CD流水线之6--构建邮件状态通知

    一. 前提 前提: 服务器开启邮箱服务: 二. 基础配置 需要安装一个插件: 插件: Email Extension Plugin 进行配置: 系统管理->系统设置-> 相关配置如下图: ...

  2. oracle wm_concat函数 列转行 分组函数

    (1)select mark, wm_concat(status) from DISSENT_INFO t GROUP BY mark; 查出来的数据 mark     status 222      ...

  3. shell中的命令与特殊符号

    1.记录命令:! !!:连续的“!”表示执行上一次的指令 !n:表示执行命令历史中第二条指令 注:!2居然给我关机了 !字符串(字符串大于1)表示执行命令历史中最近的一次 2.通配符 " * ...

  4. Vue 中怎么发起请求(二)

    fetch 是新一代XMLHttpRequest的一种替代方案.无需安装其他库.可以在浏览器中直接提供其提供的api轻松与后台进行数据交互. 基本用法: 1 fetch(url,{parmas}).t ...

  5. 转 使用SwingBench 对Oracle RAC DB性能 压力测试

    ###########说明1: 1 Swingbench 简述 1.1 概述 这是Oracle UK的一个员工在一个被抛弃的项目的基础上开发的.目前稳定版本2.2,最新版本2.3,基于JDK1.5.该 ...

  6. mysql5.7脚本日常使用

    #查看数据库物理存放目录show variables like "%datadir%";#查看所有数据库show databases#选择数据库use your_db_name#查 ...

  7. Kafka monitoring监控

    一.Metrics kafka有两个metrics包,在看源码的时候很容易混淆 package kafka.metrics package org.apache.kafka.common.metric ...

  8. python 层次索引交换级别以及排序问题

  9. javascript获取浏览器高度与宽度信息

    网页可见区域宽:document.body.clientWidth网页可见区域高:document.body.clientHeight网页可见区域宽:document.body.offsetWidth ...

  10. maya安装错误

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