POJ 1964 City Game

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.


【题目分析】
单调栈的题目,复制以前的代码水过。


【代码】

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAX_N = 100005;
int deep[1001], stack[1001], A[1001], n,m;
int map[1001][1001];
int h[1001][1001];
char ch;
int main()
{
    int tt;
    scanf("%d",&tt);
    while (tt--)
    {
        memset(deep,0,sizeof deep);
        memset(stack,0,sizeof stack);
        memset(A,0,sizeof A);
        memset(h,0,sizeof h);
        int out=0;
        scanf("%d%d",&m,&n);
        for (int i=1;i<=m;++i)
            for (int j=1;j<=n;++j)
            {
                cin>>ch;
                if (ch=='F') map[i][j]=1;
                else map[i][j]=0;
            }
        for (int i=1;i<=m;++i)
            for (int j=1;j<=n;++j)
                if (map[i][j]) h[i][j]=h[i-1][j]+1;
        for (int j=1;j<=m;++j)
        {
            for (int i = 1; i <= n; i++)
                A[i]=h[j][i];
            A[n+1] =0;n++;
            stack[0] = 0;
            int ans = 0;
            deep[0] = 0;
            int top = 1;
            for (int i = 1; i <= n; i++)
            {
                int depth = i;
                while (A[i] < stack[top-1])
                {
                    int tmp = (int)(i - deep[top-1]) * (int)stack[top-1];
                    if (tmp > ans) ans = tmp;
                    depth = deep[top-1];
                    top --;
                }
                if (A[i] > stack[top-1])
                {
                    stack[top] = A[i];
                    deep[top] = depth;
                    top ++;
                }
            }
            out=max(ans,out);
            n--;
        }
        printf("%d\n",out*3);

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值