题目链接

题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树。输出数目

思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做。

 //
#include <stdio.h>
#include <string.h>
#include <iostream> using namespace std ; int mapp[][] ; int main()
{
int N ,S,T ,W,H;
while(scanf("%d",&N) != EOF && N)
{
int x,y ;
memset(mapp,,sizeof(mapp)) ;
scanf("%d %d",&W,&H) ;
for(int i = ; i < N ; i++)
{
scanf("%d %d",&x,&y) ;
mapp[x][y] = ;
}
scanf("%d %d",&S,&T) ;
for(int i = ; i <= W ; i++)
for(int j = ; j <= H ; j++)
mapp[i][j] += (mapp[i-][j]+mapp[i][j-]-mapp[i-][j-]) ;
int ans = - ;
for(int i = S ; i <= W ;i ++)
{
for(int j = T ; j <= H ; j++)
{
ans = max(ans,mapp[i][j]-mapp[i-S][j]-mapp[i][j-T]+mapp[i-S][j-T]) ;
}
}
printf("%d\n",ans) ;
}
return ;
}

二维树状数组

 #include<iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#define MAX 102
using namespace std;
int c[MAX][MAX];
int lowbit(int x)
{
return x & (-x);
}
void add( int x,int y)
{
int i=x,j=y;
for(i=x;i<MAX;i+=lowbit(i))
for(j=y;j<MAX;j+=lowbit(j))
c[i][j]++;
}
int sum(int x,int y)
{
int i,k,sum = ;
for(i=x; i>; i-=lowbit(i))
for(k=y; k>; k-=lowbit(k))
sum += c[i][k];
return sum;
}
int main()
{
int w,h,i,j,s,t,n;
int x,y,ans;
while(scanf("%d",&n))
{
if(n==)break;
memset(c,,sizeof(c));
scanf("%d%d",&w,&h);
for(i=;i<n;i++)
{
scanf("%d%d",&x,&y);
add(x,y);
}
scanf("%d%d",&s,&t);
ans=;
for(i=s;i<=w;i++)
{
for(j=t;j<=h;j++)
{
ans=max(ans,sum(i,j)-sum(i-s,j)-sum(i,j-t)+sum(i-s,j-t));
}
}
printf("%d\n",ans);
}
}

POJ 2029 Get Many Persimmon Trees(DP||二维树状数组)的更多相关文章

  1. POJ 2029 Get Many Persimmon Trees (二维树状数组)

    Get Many Persimmon Trees Time Limit:1000MS    Memory Limit:30000KB    64bit IO Format:%I64d & %I ...

  2. POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】

    题意:给出一个h*w的矩形,再给出n个坐标,在这n个坐标种树,再给出一个s*t大小的矩形,问在这个s*t的矩形里面最多能够得到多少棵树 二维的树状数组,求最多能够得到的树的时候,因为h,w都不超过50 ...

  3. Get Many Persimmon Trees_枚举&&二维树状数组

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

  4. hdu6078 Wavel Sequence dp+二维树状数组

    //#pragma comment(linker, "/STACK:102400000,102400000") /** 题目:hdu6078 Wavel Sequence 链接:h ...

  5. POJ_1195 Mobile phones 【二维树状数组】

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013912596/article/details/33802561 题目链接:id=1195&qu ...

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

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

  7. POJ2029:Get Many Persimmon Trees(二维树状数组)

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

  8. POJ 2029 (二维树状数组)题解

    思路: 大力出奇迹,先用二维树状数组存,然后暴力枚举 算某个矩形区域的值的示意图如下,代码在下面慢慢找... 代码: #include<cstdio> #include<map> ...

  9. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

随机推荐

  1. 读取XML

    public sealed class ConfigManger { public XDocument XmlDocs { set; get; } string path = @"{0}\C ...

  2. js实现雪花飘落效果的代码

    使用js实现雪花飘落的效果,用html5绘布加js写的雪花飘效果 . 代码: <html> <head> <script> /** * js与html5实现的雪花飘 ...

  3. openerp学习笔记 错误、警告、提示、确认信息显示

    1.检查业务逻辑中的错误,终止代码执行,显示错误或警告信息: raise osv.except_osv(_('Error!'), _('Error Message.')) 示例代码: #删除当前销售单 ...

  4. Spark 大数据平台 Introduction part 2 coding

    Basic Functions sc.parallelize(List(1,2,3,4,5,6)).map(_ * 2).filter(_ > 5).collect() *** res: Arr ...

  5. MySQL在ROW模式下通过binlog提取SQL语句

    Linux基于row模式的binlog,生成DML(insert/update/delete)的rollback语句通过mysqlbinlog -v 解析binlog生成可读的sql文件提取需要处理的 ...

  6. Barracuda VS antelope

    version : 5.6.16-64.0-56-log Innodb 行存储:Innodb Plugin新引入Barracuda梭子鱼,包含Compressed和Dynamic两种行格式.而Comp ...

  7. c++异常详解

    一.什么是异常处理 一句话:异常处理就是处理程序中的错误. 二.为什么需要异常处理,以及异常处理的基本思想 C++之父Bjarne Stroustrup在<The C++ Programming ...

  8. Context详解

    前言 Context在android中的作用不言而喻,当我们访问当前应用的资源,启动一个新的activity的时候都需要提供Context,而这个Context到底是什么呢,这个问题好像很好回答又好像 ...

  9. [ios]ipad下的splitViewController 让你的APP看起来酷酷的!

    在ipad下可以使用splitViewController splitViewController下包含两个viewController 这是一种将屏幕一分为二的方式. 在水平状态下会出现成两个左右两 ...

  10. thinkphp通行证服务,验证登录,注销登录

    <?php /** * 通行证服务 */ class PassportService extends Service { /** * 验证用户或者管理员是否已登录 * @return boole ...