POJ 2029 Get Many Persimmon Trees(DP||二维树状数组)
题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树。输出数目
思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做。
- //
- #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||二维树状数组)的更多相关文章
- POJ 2029 Get Many Persimmon Trees (二维树状数组)
Get Many Persimmon Trees Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I ...
- POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】
题意:给出一个h*w的矩形,再给出n个坐标,在这n个坐标种树,再给出一个s*t大小的矩形,问在这个s*t的矩形里面最多能够得到多少棵树 二维的树状数组,求最多能够得到的树的时候,因为h,w都不超过50 ...
- Get Many Persimmon Trees_枚举&&二维树状数组
Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...
- hdu6078 Wavel Sequence dp+二维树状数组
//#pragma comment(linker, "/STACK:102400000,102400000") /** 题目:hdu6078 Wavel Sequence 链接:h ...
- POJ_1195 Mobile phones 【二维树状数组】
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013912596/article/details/33802561 题目链接:id=1195&qu ...
- POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】
<题目链接> 题目大意: 给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点. 解题分析:二维树状数组模板题. #include <cstdio ...
- POJ2029:Get Many Persimmon Trees(二维树状数组)
Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...
- POJ 2029 (二维树状数组)题解
思路: 大力出奇迹,先用二维树状数组存,然后暴力枚举 算某个矩形区域的值的示意图如下,代码在下面慢慢找... 代码: #include<cstdio> #include<map> ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
随机推荐
- BCB6中SCALERICHVIEW加入GIF动画
记载下,花了不少时间. 1. 项目导入文件GIFImage.pas 来源:http://melander.dk/delphi/gifimage/ 2. 项目导入文件RVGifAnimate.pas ...
- WEB-INF简介
WEB-INF简介 WEB-INF是Java的WEB应用的安全目录.所谓安全就是客户端无法访问,只有服务端可以访问的目录. 如果想在页面中直接访问其中的文件,必须通过web.xml文件对要访问的文件进 ...
- 【原】Infragistics.Win.UltraWinGrid.UltraGrid 增加行号
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayo ...
- Mongodb地理空间索引
1.索引: 建立索引既耗时也费力,还需要消耗很多资源.使用{"bakckground":true}选项可以使这个过程在后台完成,同时正常处理请求.如果不包括background 这 ...
- Hbase 0.95.2介绍及下载地址
HBase是一个分布式的.面向列的开源数据库,该技术来源于Google论文“Bigtable:一个结构化数据的分布式存储系统”.就像Bigtable利用了Google文件系统(File System) ...
- 利用Unicode属性移除文本中的标点符号
原文:http://bbs.csdn.net/topics/270033191 摘抄: str = str.replaceAll("[\\pP‘’“”]", "&qu ...
- Python开发【第一篇】Python基础之函数递归
函数递归 递归的本质: 就是一个函数调用另外一个函数. def d(): return '123' def c(): r = d() return r def b(): r = c() return ...
- openerp学习笔记 计算字段支持搜索
示例1: # -*- encoding: utf-8 -*-import poolerimport loggingimport netsvcimport toolslogger = netsvc.Lo ...
- 把数组排成最小的数/1038. Recover the Smallest Number
题目描述 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323. Give ...
- ActiveMQ之Queue
Queue实现的是点到点模型,在以下的例子中,启动2个消费者共同监听一个Queue,然后循环给这个Queue发送多个消息. 代码如下: public class QueueTest { /** * @ ...