题目链接

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

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

  1. //
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <iostream>
  5.  
  6. using namespace std ;
  7.  
  8. int mapp[][] ;
  9.  
  10. int main()
  11. {
  12. int N ,S,T ,W,H;
  13. while(scanf("%d",&N) != EOF && N)
  14. {
  15. int x,y ;
  16. memset(mapp,,sizeof(mapp)) ;
  17. scanf("%d %d",&W,&H) ;
  18. for(int i = ; i < N ; i++)
  19. {
  20. scanf("%d %d",&x,&y) ;
  21. mapp[x][y] = ;
  22. }
  23. scanf("%d %d",&S,&T) ;
  24. for(int i = ; i <= W ; i++)
  25. for(int j = ; j <= H ; j++)
  26. mapp[i][j] += (mapp[i-][j]+mapp[i][j-]-mapp[i-][j-]) ;
  27. int ans = - ;
  28. for(int i = S ; i <= W ;i ++)
  29. {
  30. for(int j = T ; j <= H ; j++)
  31. {
  32. ans = max(ans,mapp[i][j]-mapp[i-S][j]-mapp[i][j-T]+mapp[i-S][j-T]) ;
  33. }
  34. }
  35. printf("%d\n",ans) ;
  36. }
  37. return ;
  38. }

二维树状数组

  1. #include<iostream>
  2. #include<math.h>
  3. #include<stdio.h>
  4. #include<string.h>
  5. #define MAX 102
  6. using namespace std;
  7. int c[MAX][MAX];
  8. int lowbit(int x)
  9. {
  10. return x & (-x);
  11. }
  12. void add( int x,int y)
  13. {
  14. int i=x,j=y;
  15. for(i=x;i<MAX;i+=lowbit(i))
  16. for(j=y;j<MAX;j+=lowbit(j))
  17. c[i][j]++;
  18. }
  19. int sum(int x,int y)
  20. {
  21. int i,k,sum = ;
  22. for(i=x; i>; i-=lowbit(i))
  23. for(k=y; k>; k-=lowbit(k))
  24. sum += c[i][k];
  25. return sum;
  26. }
  27. int main()
  28. {
  29. int w,h,i,j,s,t,n;
  30. int x,y,ans;
  31. while(scanf("%d",&n))
  32. {
  33. if(n==)break;
  34. memset(c,,sizeof(c));
  35. scanf("%d%d",&w,&h);
  36. for(i=;i<n;i++)
  37. {
  38. scanf("%d%d",&x,&y);
  39. add(x,y);
  40. }
  41. scanf("%d%d",&s,&t);
  42. ans=;
  43. for(i=s;i<=w;i++)
  44. {
  45. for(j=t;j<=h;j++)
  46. {
  47. ans=max(ans,sum(i,j)-sum(i-s,j)-sum(i,j-t)+sum(i-s,j-t));
  48. }
  49. }
  50. printf("%d\n",ans);
  51. }
  52. }

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. BCB6中SCALERICHVIEW加入GIF动画

    记载下,花了不少时间. 1.  项目导入文件GIFImage.pas 来源:http://melander.dk/delphi/gifimage/ 2.  项目导入文件RVGifAnimate.pas ...

  2. WEB-INF简介

    WEB-INF简介 WEB-INF是Java的WEB应用的安全目录.所谓安全就是客户端无法访问,只有服务端可以访问的目录. 如果想在页面中直接访问其中的文件,必须通过web.xml文件对要访问的文件进 ...

  3. 【原】Infragistics.Win.UltraWinGrid.UltraGrid 增加行号

    private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayo ...

  4. Mongodb地理空间索引

    1.索引: 建立索引既耗时也费力,还需要消耗很多资源.使用{"bakckground":true}选项可以使这个过程在后台完成,同时正常处理请求.如果不包括background 这 ...

  5. Hbase 0.95.2介绍及下载地址

    HBase是一个分布式的.面向列的开源数据库,该技术来源于Google论文“Bigtable:一个结构化数据的分布式存储系统”.就像Bigtable利用了Google文件系统(File System) ...

  6. 利用Unicode属性移除文本中的标点符号

    原文:http://bbs.csdn.net/topics/270033191   摘抄: str = str.replaceAll("[\\pP‘’“”]", "&qu ...

  7. Python开发【第一篇】Python基础之函数递归

    函数递归 递归的本质: 就是一个函数调用另外一个函数. def d(): return '123' def c(): r = d() return r def b(): r = c() return ...

  8. openerp学习笔记 计算字段支持搜索

    示例1: # -*- encoding: utf-8 -*-import poolerimport loggingimport netsvcimport toolslogger = netsvc.Lo ...

  9. 把数组排成最小的数/1038. Recover the Smallest Number

    题目描述 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323.   Give ...

  10. ActiveMQ之Queue

    Queue实现的是点到点模型,在以下的例子中,启动2个消费者共同监听一个Queue,然后循环给这个Queue发送多个消息. 代码如下: public class QueueTest { /** * @ ...