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 y2)
{
    return num[x2][y2]-num[x2][y1]-num[x1][y2]+num[x1][y1];
}
int max(int a,int b)
{
    if(a<b)a=b;
    return a;
}
int main()
{
    int n,x,y,w,h,c,k;
    while(scanf("%d",&n),n)
    {
        memset(num,0,sizeof(num));
        scanf("%d%d",&w,&h);
        for(int i=0; i<n; i++)
        {
            scanf("%d%d",&x,&y);
            num[x][y]=1;
        }
        scanf("%d%d",&c,&k);
        for(int i=1; i<=w; i++)
        {
            int sum=0;
            for(int j=1; j<=h; j++)
            {
                sum+=num[i][j];
                if(i!=1)
                {
                    num[i][j]=num[i-1][j];
                }
                else
                {
                    num[i][j]=0; //这里开始时收残了~~记住要初始化 ,否则就加两倍了~~
                }
                num[i][j]+=sum;
            }
        }
        int min1=0;
        for(int i=0;i+c<=w;i++)
        {
            for(int j=0;j+k<=h;j++)
            {
                min1=max(min1,cal(i,j,i+c,j+k));
            }
        }
        printf("%d\n",min1);
    }
    return 0;
}

POJ 2029 Get Many Persimmon Trees

时间: 2024-08-15 14:20:44

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 (二维树状数组)

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,暴力。

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 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

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 2029

Get Many Persimmon Trees Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3700   Accepted: 2405 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

poj2029--Get Many Persimmon Trees(dp)

Get Many Persimmon Trees Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3708   Accepted: 2410 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