• UVALive


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

    Output

    For each data set in the input file 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.

    题解:

      这个题目有点难想,我只想到一个n^3方的暴力。

      对于一个点,我们维护三个信息,1.他向上最大能延伸到哪里(up[i][j]),把他向上延伸的网格看成一条线。2.他向带着这根线最多可以延伸到哪里lt[i][j]。3.他带着这根线向右最多可以延伸到哪里rt[i][j]。

      然后我们枚举格点,最大的up[i][j]*(right[i][j]-left[i][j]+1)就是答案,因为up[i][j]*(right[i][j]-left[i][j]+1)就相当于是在i行以上的包括(i,j)的最大矩形的面积,就可以求出答案了。

    代码:

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    #define MAXN 1200
    using namespace std;
    int lt[MAXN][MAXN],rt[MAXN][MAXN],up[MAXN][MAXN],mp[MAXN][MAXN];
    int n,m;
    
    void cl(){
        memset(lt,0,sizeof(lt));
        memset(rt,0,sizeof(rt));
        memset(up,0,sizeof(up));
        memset(mp,0,sizeof(mp));
    }
    
    void work(){
        cl();
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                char ch=getchar();
                while(ch!='R'&&ch!='F') ch=getchar();
                mp[i][j]=(ch=='R');
            }
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            int hh=0;
            for(int j=1;j<=m;j++){
                if(mp[i][j]) up[i][j]=lt[i][j]=0,hh=j;
                else{
                    if(i==1) up[i][j]=1,lt[i][j]=hh+1;
                    else          up[i][j]=up[i-1][j]+1,lt[i][j]=max(hh+1,lt[i-1][j]);
                }
            }
            hh=m+1;
            for(int j=m;j>=1;j--){
                if(mp[i][j]) rt[i][j]=m+1,hh=j;
                else{
                    if(i==1) rt[i][j]=hh-1;
                    else          rt[i][j]=min(hh-1,rt[i-1][j]);
                }
                ans=max(ans,(rt[i][j]-lt[i][j]+1)*up[i][j]);
            }
        }
        printf("%d
    ",ans*3);
    }
    
    int main()
    {
        int t;cin>>t;
        while(t--){
            work();
        }
        return 0;
    }
  • 相关阅读:
    浪漫与苦闷的变奏
    连长和教导员
    怀念的怀念
    springboot 配置 swagger常见版本不匹配问题解决方案
    国家政策与理想导向
    python socket web
    python包源码安装与卸载
    ubuntu安装polipo
    arm交叉编译busybox
    交叉编译python3.9.13
  • 原文地址:https://www.cnblogs.com/renjianshige/p/7649377.html
Copyright © 2020-2023  润新知