题意:给出一个h*w的矩形,再给出n个坐标,在这n个坐标种树,再给出一个s*t大小的矩形,问在这个s*t的矩形里面最多能够得到多少棵树

二维的树状数组,求最多能够得到的树的时候,因为h,w都不超过500,直接暴力

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int c[maxn][maxn]; int lowbit(int x){ return x & (-x);} int sum(int x,int y){
int ret=;
int y1;
while(x > ){
y1=y;
while(y1 > ){
ret += c[x][y1];y1-=lowbit(y1);
}
x-=lowbit(x);
}
return ret;
} void add(int x,int y,int d){
int y1;
while(x < maxn){
y1=y;
while(y1 < maxn){
c[x][y1] += d;y1+=lowbit(y1);
}
x+=lowbit(x);
}
} int main(){
int n;
while(scanf("%d",&n)!=EOF && n){
memset(c,,sizeof(c));
int w,h;
scanf("%d %d",&w,&h);
while(n--){
int u,v;
scanf("%d %d",&u,&v);
add(v,u,);
}
int x,y;
scanf("%d %d",&x,&y);swap(x,y); int ans=-;
int tmp=;
for(int i=;i <=h;i++){
for(int j=;j<=w;j++){
tmp = sum(i+x-,j+y-)-sum(i-,j+y-)-sum(i+x-,j-)+sum(i-,j-);
ans = max(ans,tmp);
}
}
printf("%d\n",ans);
}
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. struts2学习之基础笔记1

    第6章 Strusts 2框架 1  引出 Web App  àà MVC  àà View 视图(jsp,html,JS) | C(Servlet)Filter,Listneer | M(数据bea ...

  2. 【Paper Reading】Learning while Reading

    Learning while Reading 不限于具体的书,只限于知识的宽度 这个系列集合了一周所学所看的精华,它们往往来自不只一本书 我们之所以将自然界分类,组织成各种概念,并按其分类,主要是因为 ...

  3. Win10 build package error collections

    1. 打包Released的时候出现问题意思是说 本地项目,类里有这个Visibility属性不能进行序列化 严重性 代码 说明 项目 文件 行 禁止显示状态 错误 error CS0029: 无法将 ...

  4. Reflection (computer programming) -反射-自身结构信息

    n computer science, reflection is the ability of a computer program to examine, introspect, and modi ...

  5. Codeforces Round #493 (Div. 2) C. Convert to Ones 乱搞_构造_好题

    题意: 给你一个长度为 nnn 的 010101串 ,你有两种操作: 1.将一个子串翻转,花费 XXX 2.将一个子串中的0变成1,1变成0,花费 YYY 求你将这个01串变成全是1的串的最少花费. ...

  6. C#RichTextBox复制并跳转指定行

    方法一: rTxt.Focus(); //设置文本框中选定的文本起始点 为 指定行数第一个字符的索引 rTxt.SelectionStart = rTxt.GetFirstCharIndexFromL ...

  7. [读书笔记] R语言实战 (六) 基本图形方法

    1.  条形图 barplot() #载入vcd包 library(vcd) #table函数提取各个维度计数 counts <- table(Arthritis$Improved) count ...

  8. sql limit 的用法

    sql语句里的limit使用方法 .    SELECT * FROM table  LIMIT [offset,] rows | rows OFFSET offset    在我们使用查询语句的时候 ...

  9. 用pycharm运行django项目

    [点击]run -> Edit Configrations 弹出如下页面 点击“+” 点击Django server 在弹出页面的host填0.0.0.0 点击这个“文件夹” 点击‘+’后填下面 ...

  10. dockerfile centos+jdk+时区设置

    1.参考博客:https://blog.csdn.net/yjk13703623757/article/details/68944549 2.dockerfile如下 # Base os image ...