HDU 1506 City Game by Assassin

DP 专栏收录该内容
27 篇文章 0 订阅

Problem Description
Bob is a strategy game programming specialist. In his new city building game the gaming environment is as follows: a city is built up by areas, in which there are streets, trees,factories and buildings. There is still some space in the area that is unoccupied. The strategic task of his game is to win as much rent money from these free spaces. To win rent money you must erect buildings, that can only be rectangular, as long and wide as you can. Bob is trying to find a way to build the biggest possible building in each area. But he comes across some problems – he is not allowed to destroy already existing buildings, trees, factories and streets in the area he is building in.

Each area has its width and length. The area is divided into a grid of equal square units.The rent paid for each unit on which you’re building stands is 3$.

Your task is to help Bob solve this problem. The whole city is divided into K areas. Each one of the areas is rectangular and has a different grid size with its own length M and width N.The existing occupied units are marked with the symbol R. The unoccupied units are marked with the symbol F.

Input
The first line of the input contains an integer K – determining the number of datasets. Next lines contain the area descriptions. One description is defined in the following way: The first line contains two integers-area length M<=1000 and width N<=1000, separated by a blank space. The next M lines contain N symbols that mark the reserved or free grid units,separated by a blank space. The symbols used are:

R – reserved unit

F – free unit

In the end of each area description there is a separating line.

Output
For each data set in the input print on a separate line, on the standard output, the integer that represents the profit obtained by erecting the largest building in the area encoded by the data set.

Sample Input
2
5 6
R F F F F F
F F F F F F
R R R F F F
F F F F F F
F F F F F F

5 5
R R R R R
R R R R R
R R R R R
R R R R R
R R R R R

Sample Output
45
0

思路:
要说思路也是简单,这是1506问题的一个二维化,求一个长方体的最大面积,我们可以这样处理,从第一层向下遍历,用Value代表类似长方形的高,一旦出现R value[i]就置零,出现F value[i]加1,这样就保证了所有的长方形都是从底边起始的。在用1506的方法遍历每一层,更新最大值即可
不太明白每一层怎么处理的可以参考如下
HUD 1506

#include<bits/stdc++.h>
#define input freopen("input.txt","r",stdin)
using namespace std;
long long l[1010],r[1010];
long long value[1010],maxx;
char c[1004][1004]; 
int main()
{
    input;
    int n,m,i,j,t,k;
    int left,right;
    while(cin>>t)
    {
        while(t--)
        {
            cin>>n>>m;
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=m;j++)
                {
                    cin>>c[i][j];
                }
            }
            memset(value,0,sizeof(value));
            for(maxx=0,i=1;i<=n;i++)
            {
                for(j=1;j<=m;j++)
                {
                    if(c[i][j]=='F')
                    {
                        value[j]+=1;
                    }
                    else
                    {
                        value[j]=0;
                    }
                }
                memset(l,0,sizeof(l));
                memset(r,0,sizeof(r));
                l[1]=1;
                for(j=2;j<=m;j++)
                {
                    left=j;
                    while(1)
                    {
                        if(left==1)break;
                        if(value[left-1]>=value[j])
                        {
                            left=l[left-1];
                        }
                        else
                        {
                            break;
                        }
                    }
                    l[j]=left;
                }
                r[m]=m;
                for(j=m-1;j>=1;j--)
                {
                    right=j;
                    while(1)
                    {
                        if(right==n)break;
                        if(value[right+1]>=value[j])
                        {
                            right=r[right+1];
                        }
                        else
                        {
                            break;
                        }
                    }
                    r[j]=right;
                }
                for(j=1;j<=m;j++)   //判断从上到下每一层的最大值 
                {
                    if(maxx<(r[j]-l[j]+1)*value[j])
                    {
                        maxx=(r[j]-l[j]+1)*value[j];
                    }
                }
            }
            cout<<3*maxx<<endl;
        }
    } 
    return 0;
}
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值