(简单) POJ 2029 Get Many Persimmon Trees,暴力。
Description
For example, in Figure 1, the entire field is a rectangular grid whose width and height are 10 and 8 respectively. Each asterisk (*) represents a place of a persimmon tree. If the specified width and height of the estate are 4 and 3 respectively, the area surrounded by the solid line contains the most persimmon trees. Similarly, if the estate's width is 6 and its height is 4, the area surrounded by the dashed line has the most, and if the estate's width and height are 3 and 4 respectively, the area surrounded by the dotted line contains the most persimmon trees. Note that the width and height cannot be swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure 1.
Figure 1: Examples of Rectangular Estates
Your task is to find the estate of a given size (width and height) that contains the largest number of persimmon trees.
// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月20日 星期一 09时57分41秒
// File Name : 2029.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; int W,H;
int N;
int map1[][];
int S,T; int sum(int x1,int y1,int x2,int y2)
{
return map1[x2][y2]-map1[x1-][y2]-map1[x2][y1-]+map1[x1-][y1-];
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int a,b; while(~scanf("%d",&N) && N)
{
memset(map1,,sizeof(map1));
scanf("%d %d",&W,&H); for(int i=;i<=N;++i)
{
scanf("%d %d",&a,&b);
map1[a][b]=;
} scanf("%d %d",&S,&T); for(int i=;i<=W;++i)
for(int j=;j<=H;++j)
map1[i][j]+=map1[i][j-]; for(int j=;j<=H;++j)
for(int i=;i<=W;++i)
map1[i][j]+=map1[i-][j]; int ans=; for(int i=;i+S-<=W;++i)
for(int j=;j+T-<=H;++j)
ans=max(ans,sum(i,j,i+S-,j+T-)); printf("%d\n",ans);
} return ;
}
(简单) POJ 2029 Get Many Persimmon Trees,暴力。的更多相关文章
- 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
Get Many Persimmon Trees Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3243 Accepted: 2 ...
- poj 2029 Get Many Persimmon Trees 各种解法都有,其实就是瞎搞不算吧是dp
连接:http://poj.org/problem?id=2029 题意:给你一个map,然后在上面种树,问你h*w的矩形上最多有几棵树~这题直接搜就可以.不能算是DP 用树状数组也可作. #incl ...
- POJ 2029 Get Many Persimmon Trees(DP||二维树状数组)
题目链接 题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树.输出数目 思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做. #include <stdio ...
- poj 2029 Get Many Persimmon Trees (dp)
题目链接 又是一道完全自己想出来的dp题. 题意:一个w*h的图中,有n个点,给一个s*t的圈,求这个圈能 圈的最多的点 分析:d[i][j]代表i行j列 到第一行第一列的这个方框内有多少个点, 然后 ...
- POJ 2029 Get Many Persimmon Trees(水题)
题意:在w*h(最大100*100)的棋盘上,有的格子中放有一棵树,有的没有.问s*t的小矩形,最多能含有多少棵树. 解法:最直接的想法,设d[x1][y1][x2][y2]表示选择以(x1, y1) ...
- POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】
<题目链接> 题目大意: 给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点. 解题分析:二维树状数组模板题. #include <cstdio ...
- POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】
题意:给出一个h*w的矩形,再给出n个坐标,在这n个坐标种树,再给出一个s*t大小的矩形,问在这个s*t的矩形里面最多能够得到多少棵树 二维的树状数组,求最多能够得到的树的时候,因为h,w都不超过50 ...
- poj2029 Get Many Persimmon Trees
http://poj.org/problem?id=2029 单点修改 矩阵查询 二维线段树 #include<cstdio> #include<cstring> #inclu ...
随机推荐
- Servlet与jsp间的传值问题
Servlet与JSP 之间的传值有两种情况:JSP -> Servlet, Servlet -> JSP.通过对象 request和 session (不考虑 application)完 ...
- TCPIP header
tcp packet: tcp header: ip header:
- GameUnity 2.0 文档(三) 纸片人八方向
DirectSprite类 有别于 上篇文档出现的 AnimationSprite类 (从头播放到尾) 这个类根据 path的图,如果是 8*8 64个图 八方向,可以设置长宽和 角度 角度 代表 8 ...
- cordova插件开发-1
这是初级编,实现了js调用Android代码 首先需要编写java代码: public class AppUpdate extends CordovaPlugin { @Override public ...
- 剑指offer 数字在排序数组中出现的次数
因为有序 所以用二分法,分别找到第一个k和最后一个k的下标.时间O(logN) class Solution { public: int GetNumberOfK(vector<int> ...
- Application对象
Application对象报讯是应用程序参数的额,多个用户可以共享一个Application.用于启动和管理ASP.NET应用程序. Count 属性 获取Application对象变量的个数,集合 ...
- 【抽屉定理】 组合数学poj2356
假定n个数为a1,a2,...,an,前n项和分别是S1.S2.....Sn,那么如果有一个Si模n是0,就是答案,否则,n个数模n的余数只能在 1到n - 1之间,把余数作为抽屉,显然n个数放到n ...
- 2016大连网络赛 Different GCD Subarray Query
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- Android------自定义ListView详解
引自:http://www.cnblogs.com/phonegap/archive/2011/04/28/2535732.html 在这里我就对自定义ListView进行讲解下吧,直入真题吧,首先我 ...
- JS读RSS
<html> <head> <title>javascript读取RSS数据</title> <META content="t ...