UVA 1330 LA 3029 seerc 2004 - City Game


Bob is a strategy game programming specialist. In his new city building game thegaming 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 strategictask of his game is to win as much rent money from these free spaces. To win rent money youmust erect buildings, that can only be rectangular, as long and wide as you can. Bob is trying tofind a way to build the biggest possible building in each area. But he comes across someproblems � he is not allowed to destroy already existing buildings, trees, factories and streets inthe 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. Eachone 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 markedwith the symbol F.

Input 

The first line of the input file contains an integer K � determining the number ofdatasets. Next lines contain the area descriptions. One description is defined in the followingway: The first line contains two integers-area length M<=1000 and width N<=1000, separated bya 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, theinteger that represents the profit obtained by erecting the largest building in the area encoded bythe 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

题目大意:给定N*M的矩阵,其中一些格子是空地(F),其他是障碍(R)。求全部又空地组成的最大矩阵,结果×3.



用三个数组记录递推一个格子往上,往左,往右的障碍格位置。全部扫描一遍即可。


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <set>

using namespace std;

#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#endif

#define S64I(a) scanf(iform, &(a))
#define P64I(a) printf(oform, (a))


const int INF = 0x3f3f3f3f;
const int maxn = 1000 + 50;

int gleft[maxn][maxn];
int gright[maxn][maxn];
int up[maxn][maxn];
int G[maxn][maxn];

int main() {
	int kase;

	scanf("%d", &kase);
	while(kase--) {
		int n, m;
		scanf("%d%d", &n, &m);
		for(int i=0; i<n; i++) {
			for(int j=0; j<m; j++) {
				char ch = getchar();
				while(ch!='F' && ch!='R') ch = getchar();
				G[i][j] = ch == 'F' ? 0 : 1;
			}
		}
		int ans = 0;
		int lo=-1;
		for(int i=0; i<m; i++) {
			up[0][i] = -1 + G[0][i];
			if(G[0][i]) lo = i;
			gleft[0][i] = lo;
		}
		int ro=m;
		for(int i=m-1; i>=0; i--) {
			if(G[0][i]) ro = i;
			gright[0][i] = ro;
			int w = gright[0][i] - gleft[0][i] - 1;
			int h = 0 - up[0][i];
			if(w > 0 && h > 0) {
				int t = w * h;
				if(t > ans) {
					ans = t;
				}
			}
		}
		for(int i=1; i<n; i++) {
			lo = -1;
			for(int j=0; j<m; j++) {
				up[i][j] = G[i][j] ? i : up[i-1][j];
				if(G[i][j]) lo = j;
				if(G[i-1][j]) {
					gleft[i][j] = lo;
				} else {
					gleft[i][j] = max(lo, gleft[i-1][j]);
				}
			}
			ro = m;
			for(int j=m-1; j>=0; j--) {
				if(G[i][j]) ro = j;
				if(G[i-1][j]) {
					gright[i][j] = ro;
				} else {
					gright[i][j] = min(ro, gright[i-1][j]);
				}
				int w = gright[i][j] - gleft[i][j] - 1;
				int h = i - up[i][j];
				if(w>0 && h>0) {
					int t = w * h;
					if(t > ans) {
						ans = t;
					}
				}
			}
		}
		printf("%d\n", ans*3);
	}

	return 0;
}







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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值