595

题目

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.

R - 已使用区域
F - 空闲区域

题解

**>HDU 1506.Largest Rectangle in a Histogram<** 类似

代码

/*
By:OhYee
Github:OhYee
Blog:http://www.oyohyee.com/
Email:oyohyee@oyohyee.com

かしこいかわいい？
エリーチカ！

*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
using namespace std;

const int maxn = 1005;
bool Map[maxn][maxn];

int H[maxn][maxn];
int Left[maxn][maxn];
int Right[maxn][maxn];

//int S[maxn][maxn];

void Do() {
int n,m;
scanf("%d%d",&n,&m);
memset(Map,0,sizeof(Map));
memset(H,0,sizeof(H));
memset(Left,0,sizeof(Left));
memset(Right,0,sizeof(Right));

for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++) {
char temp;
scanf("\n%c",&temp);
if(temp == 'R')
Map[i][j] = false;
else
Map[i][j] = true;
}

for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++) {
if(Map[i][j]) {
if(Map[i - 1][j])
H[i][j] = H[i - 1][j] + 1;
else
H[i][j] = 1;
}
}

for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++) {
if(Map[i][j]) {
int t = j;
while(t >= 1 && H[i][j] <= H[i][t - 1])
t = Left[i][t - 1];
Left[i][j] = t;
}
}

for(int i = 1;i <= n;i++)
for(int j = m;j >= 1;j--) {
if(Map[i][j]) {
int t = j;
while(t <= m && H[i][j] <= H[i][t + 1])
t = Right[i][t + 1];
Right[i][j] = t;
}
}

int Max = 0;
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++) {
if(Map[i][j]) {
int S = H[i][j]*(Right[i][j] - Left[i][j] + 1);
Max = max(Max,S);
}
}

printf("%d\n",Max*3);
}

int main() {
int T;
scanf("%d",&T);
while(T--)
Do();
return 0;
}

• 点击查看/关闭被识别为广告的评论