(简单) POJ 2029 Get Many Persimmon Trees,暴力。

Description

Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate was strictly specified by the lord, he was allowed to choose any location for the estate in the field. Inside the field which had also a rectangular shape, many Japanese persimmon trees, whose fruit was one of the famous products of the Aizu region known as ‘Mishirazu Persimmon‘, were planted. Since persimmon was Hayashi‘s favorite fruit, he wanted to have as many persimmon trees as possible in the estate given by the lord. 
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[110][110];
int S,T;

int sum(int x1,int y1,int x2,int y2)
{
    return map1[x2][y2]-map1[x1-1][y2]-map1[x2][y1-1]+map1[x1-1][y1-1];
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int a,b;

    while(~scanf("%d",&N) && N)
    {
        memset(map1,0,sizeof(map1));
        scanf("%d %d",&W,&H);

        for(int i=1;i<=N;++i)
        {
            scanf("%d %d",&a,&b);
            map1[a][b]=1;
        }

        scanf("%d %d",&S,&T);

        for(int i=1;i<=W;++i)
            for(int j=1;j<=H;++j)
                map1[i][j]+=map1[i][j-1];

        for(int j=1;j<=H;++j)
            for(int i=1;i<=W;++i)
                map1[i][j]+=map1[i-1][j];

        int ans=0;

        for(int i=1;i+S-1<=W;++i)
            for(int j=1;j+T-1<=H;++j)
                ans=max(ans,sum(i,j,i+S-1,j+T-1));

        printf("%d\n",ans);
    }

    return 0;
}

时间: 2024-10-08 14:55:49

(简单) POJ 2029 Get Many Persimmon Trees,暴力。的相关文章

POJ 2029 Get Many Persimmon Trees(DP)

题目链接 题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树.输出数目 思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做. 1 //2029 2 #include <stdio.h> 3 #include <string.h> 4 #include <iostream> 5 6 using namespace std ; 7 8 int mapp[110][110] ; 9 10 int main() 11 { 12 int N

POJ 2029 Get Many Persimmon Trees

这是动态规划?我一点思路怎么也没有.最后还是用矩阵部分求和枚举0MS. 题目大意: 给出一个矩阵,上面有几个点.在给一个小点儿的矩阵,求这个矩阵最多能套上几个点.(注意:小矩阵长宽给定,不能旋转). 解题思路: 建立数组num[i][j]代表点(1,1)到点(i,j)组成的矩阵里有几个点. 下面是代码: #include <stdio.h> #include <string.h> int num[105][105]; int cal(int x1,int y1,int x2,int

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

Get Many Persimmon Trees Time Limit:1000MS    Memory Limit:30000KB    64bit IO Format:%I64d & %I64u SubmitStatusPracticePOJ 2029 Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in

POJ 2029 Get Many Persimmon Trees (二维树状数组 or DP)

题意:一个H * W的大矩形,里面的某些格子种有树.现在要你找出一个h * w的小矩形,使得里面树的数量最多,问最多有多少棵树 是二维树状数组基础用法,边输入边更新有树的点,建完树后就可以查询每个(1,1)到(x,y)为对顶点的矩形中共有多少棵柿子树. 算法复杂度 O(H*W*lgH*lgW) 但是由于这题的柿子树一旦确定位置后就没有更新位置,所以不需要用树状数组也可,直接用dp统计每个(1,1)到(x,y)为对顶点的矩形中共有多少棵柿子树. 统计的状态转移方程是: for(int i=1;i<

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

题意:给出一个h*w的矩形,再给出n个坐标,在这n个坐标种树,再给出一个s*t大小的矩形,问在这个s*t的矩形里面最多能够得到多少棵树 二维的树状数组,求最多能够得到的树的时候,因为h,w都不超过500,直接暴力 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector&

【POJ 2029】 Get Many Persimmon Trees(DP)

[POJ 2029] Get Many Persimmon Trees(DP) Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4024   Accepted: 2628 Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18

POJ 2029 DP || 暴力

在大矩形中找一个小矩形 使小矩形包含的*最多 暴力或者DP  水题 暴力: #include "stdio.h" #include "string.h" int main() { int n,m,w,i,s,t,j,k,l,ans,sum,x,y; int map[101][101]; while (scanf("%d",&w)!=EOF) { if(w==0) break; scanf("%d%d",&n,&

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

Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of

(简单) POJ 3087 Shuffle&#39;m Up,枚举。

Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several