3029 - City Game

原创 2015年07月10日 17:26:06

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

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.

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
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
const int MAXN = 1010;
bool mp[MAXN][MAXN];//1为石头
int Left[MAXN][MAXN],Right[MAXN][MAXN],up[MAXN][MAXN];
char read_char()
{
    char rt = getchar();
    while(true)
    {
        if(rt=='F'||rt=='R')return rt;
        rt = getchar();
    }
}
int main()
{
    int t, i, j, n, m;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        memset(mp,1,sizeof mp);
        for(i=1; i<=n; i++)
        {
            for(j=1; j<=m; j++)
            {
                mp[i][j] = (read_char()=='R');
            }
        }
        int ans = 0;
        for(i=0; i<=n; i++)
        {
            int lo=0, ro = m+1;
            for(j=0; j<=m+1; j++)
            {
                if(mp[i][j])
                {
                    Left[i][j] = up[i][j] = 0; lo = j;
                }else{
                    Left[i][j] = max(Left[i-1][j],lo);
                    up[i][j] = up[i-1][j] + 1;
                }
            }
            for(j=m+1; j>=0; j--)
            {
                if(mp[i][j])
                {
                    Right[i][j] = m+1; ro = j;
                }else{
                    Right[i][j] = min(Right[i-1][j], ro);
                    ans = max(ans,up[i][j]*(Right[i][j]-Left[i][j]-1));
                }
            }
        }
        printf("%d\n", ans*3);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu1505 City Game二维01矩阵求最大矩形周长

City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota...
  • qiqijianglu
  • qiqijianglu
  • 2013年01月30日 21:06
  • 1561

LA 3029 - City Game (模拟&技巧)好题

Bob is a strategy game programming specialist. In his new city building game the gaming environmenti...
  • yanghui07216
  • yanghui07216
  • 2016年02月27日 10:13
  • 120

HDU 1505 City Game-dp-(最大子矩阵模型)

题意:求最大的子矩阵 分析:直接用最大字矩阵的公式做超时了。换个思路,这题跟上一题1506有关系,先以每层为底算出每个元素能到达的最大的高度,然后就跟1506一样了。这里求高度和求面积两处地方用到了...
  • AC_0_summer
  • AC_0_summer
  • 2015年06月23日 02:48
  • 545

HDU1505_City Game【最大完全子矩阵】

City Game 题目大意:给你一个M*N的区域。R代表被占用,F代表空闲。每块空闲 的区域价值3美金,求全部由空闲区域围成的矩形的价值 思路:1506的升级版。不同的是,1505是二维的。把2维...
  • u011676797
  • u011676797
  • 2014年10月20日 16:38
  • 1072

UVALive 3029 City Game(最大子矩阵+悬线法)

题意:给定一个m*n的矩阵,0表示空地,1表示障碍,找出一个由空地组成的面积最大的子矩阵,输出最大面积乘以三。 思路:直接枚举的话复杂度无法承受,考虑用扫描法。对于每一个点(i, j)可以由三个参数表...
  • u014664226
  • u014664226
  • 2015年11月09日 15:15
  • 311

City Game (最大子矩阵)

City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota...
  • l2533636371
  • l2533636371
  • 2017年04月17日 21:46
  • 136

HDU1505——City Game(扫描线)

City Game Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status ...
  • u013022160
  • u013022160
  • 2014年08月11日 14:35
  • 293

hdu1505—City Game(1506的加强版)

题目链接:传送门 City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja...
  • jiangzhiyuan123
  • jiangzhiyuan123
  • 2017年07月11日 19:46
  • 55

poj1964 City Game(最大子矩阵)

City Game Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 4783   Acce...
  • u013492736
  • u013492736
  • 2014年08月11日 16:51
  • 383

UVALive 3029 City Game 悬线法求最大子矩阵面积 dp

题目链接:点击打开链接 Bob is a strategy game programming specialist. In his new city building game the gaming...
  • qq574857122
  • qq574857122
  • 2015年01月24日 19:46
  • 934
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:3029 - City Game
举报原因:
原因补充:

(最多只允许输入30个字)