二维树状数组可解此题

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define lowbit(x) (x)&(-x) using namespace std;
int sum[105][105],k,n,m;
int W,H; void gp(int x,int y){
int t;
for(;x<=n;x+=lowbit(x))
for(t=y;t<=m;t+=lowbit(t))
sum[x][t]+=1;
} int gs(int x,int y){
int s=0,t;
for(;x;x-=lowbit(x))
for(t=y;t;t-=lowbit(t))
s+=sum[x][t];
return s;
} int gst(int x1,int y1,int x2,int y2){
return gs(x2,y2)-gs(x1-1,y2)-gs(x2,y1-1)+gs(x1-1,y1-1);
} int main(){
int s,h; int maxt;
while(scanf("%d",&k),k){
maxt=-1;
memset(sum,0,sizeof(sum));
scanf("%d%d",&n,&m);
for(int i=1;i<=k;i++){
scanf("%d%d",&s,&h);
gp(s,h);
}
scanf("%d%d",&W,&H);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
maxt=max(maxt,gst(i-W<=0?1:(i-W+1),j-H<=0?1:(j-H+1),i,j));
}
}
printf("%d\n",maxt);
}
return 0;
}

  

POJ 2029的更多相关文章

  1. poj 2029 Get Many Persimmon Trees 各种解法都有,其实就是瞎搞不算吧是dp

    连接:http://poj.org/problem?id=2029 题意:给你一个map,然后在上面种树,问你h*w的矩形上最多有几棵树~这题直接搜就可以.不能算是DP 用树状数组也可作. #incl ...

  2. (简单) POJ 2029 Get Many Persimmon Trees,暴力。

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

  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

    Get Many Persimmon Trees Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3243 Accepted: 2 ...

  5. poj 2029 二维树状数组

    思路:简单树状数组 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...

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

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

  7. poj 2029 Get Many Persimmon Trees (dp)

    题目链接 又是一道完全自己想出来的dp题. 题意:一个w*h的图中,有n个点,给一个s*t的圈,求这个圈能 圈的最多的点 分析:d[i][j]代表i行j列 到第一行第一列的这个方框内有多少个点, 然后 ...

  8. POJ 2029 Get Many Persimmon Trees(水题)

    题意:在w*h(最大100*100)的棋盘上,有的格子中放有一棵树,有的没有.问s*t的小矩形,最多能含有多少棵树. 解法:最直接的想法,设d[x1][y1][x2][y2]表示选择以(x1, y1) ...

  9. POJ 2029 DP || 暴力

    在大矩形中找一个小矩形 使小矩形包括的*最多 暴力或者DP  水题 暴力: #include "stdio.h" #include "string.h" int ...

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

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

随机推荐

  1. 关于MFC控件删除出现“具有该ID的控件已存在”这样的情况的解决方案,详细,网上都没有这么详细的,我是“深受其害”,所以想将详细的方法分享出去。

    网上关于MFC控件删除出现“具有该ID的控件已存在”这样的情况,在网上找了很多关于这方面的东西,但是都不是很全,也不容易弄明白.现在问我直接通过一个项目和图片的形式和大家一块分享一个这个解决方法(如有 ...

  2. PCB 无需解压,直接读取Zip压缩包指定文件 实现方法

    最近有一项需求,将电测试点数后台批量写入到工程系统流程指示中,而电测试文件存在压缩包中,压缩包存在公共网络盘 示例图: 一.采用原始方法(4步完成): 第1步:.网络盘ZIP拷到本地, 第2步:解压Z ...

  3. B - IQ test

    Problem description Bob is preparing to pass IQ test. The most frequent task in this test is to find ...

  4. 一种压缩图片的方法---Machine learning 之 K-Means

    背景描述: RGB编码:对于一个直接用24bit表示每一个而像素的图像来说,每一个pixel使用8-bit无符号整数(0-255)来表示红or绿or蓝. 压缩目的: 将128x128大小的图片由原来的 ...

  5. 基于NPOI的扩展

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using NPOI.HSS ...

  6. bootstrap-paginator基于bootstrap的分页插件

    bootstrap-paginator基于bootstrap的分页插件 GitHub 官网地址:https://github.com/lyonlai/bootstrap-paginator 步骤 引包 ...

  7. java与安卓中的回调callback学习笔记

    1.回调的简单设计如下: package com.listercai.top; public class A { private CallBack callBack; private AnotherC ...

  8. I2C controller core之Bit controller(02)

    4 generate clock and control signals 1 -- architecture signal iscl_oen, isda_oen : std_logic; -- int ...

  9. python学习之小小爬虫

    学习python一段时间了,写了一个图片的小小爬虫,分享下,不喜勿喷! #coding=utf-8 ''' Created on 2015-5-22 @author: 悦文 ''' import re ...

  10. webpack command not found 的意外的坑 - 原因是从node开始

    写给自己做个记录: 弄了半天 执行了下面操作 npm install webpack -g 因为小白不懂原理,所以执行了好遍,结果还是如题, webpack command not found 网上搜 ...