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 ...
随机推荐
- how to debug thread cpu 100%
when we write a program, cpu and memory usages are very important to indicate the stability of the p ...
- oc常见误区
1.同步请求可以从因特网请求数据,一旦发送同步请求,程序将停止用户交互,直至服务器返回数据完成,才可以进行下一步操作, 2.异步请求不会阻塞主线程,而会建立一个新的线程来操作,用户发出异步请求后,依然 ...
- 例题6-8 Tree Uva548
这道题我一直尝试用scanf来进行输入,不过一直没有成功,因此先搁置一下,以后积累些知识再进行尝试. 这道题有两种解决方案: 即先建树,再遍历和边建树边遍历.这两种方案经过实践证实效率相差不太多.应该 ...
- 30个HTML5学习资源
早在几个星期前,Adobe就发布了Dreamweaver CS5 HTML5 Pack的预览版下载.众所周知,HTML5在互联网领域掀起了一场大论战,并让Adobe的日子很难熬.HTML5致力于为前端 ...
- Global::validateEmail
/***************************************************************** (C) Copyright DENTSPLY Internatio ...
- 记一次Surface Pro 2还原操作
因为要做Azure的一个case,对自己的域环境下直接进行了捕获.结果导致机器直接crash. 重启后使用本地账号登陆后发现所有Win 8 的App都无法使用,包括进入设置中还原方式也无法使用. 可以 ...
- Android系统SVC命令教程
svc命令,位置在/system/bin目录下,用来管理电源控制,无线数据,WIFI # svc svc Available commands: help Show information about ...
- linux创建线程之pthread_create
说明:本文转自多线程编程之pthread_create函数应用,在此基础上笔者做了些许改动. pthread_create函数 函数简介 pthread_create是UNIX环境创建线程函数 头文件 ...
- .NET序员的成长之路
- MVC学习系列——ModelBinder扩展
在MVC系统中,我们接受数据,运用的是ModelBinder 的技术. MVC学习系列——ActionResult扩展在这个系列中,我们自定义了XmlResult的返回结果. 那么是不是意味着能POS ...