• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

LA 3029 City Game

City Game

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
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define INF 0x7fffffff
11 #define mod 1000000007
12 #define ll long long
13 #define maxn 1005
14 #define pi acos(-1.0)
15 int n, m;
16 int t;
17 int lx[maxn], rx[maxn];
18 int a[maxn][maxn], up[maxn], lf[maxn], ri[maxn];
19 int main(){
20     scanf("%d", &t);
21     while (t--){
22         scanf("%d%d", &n, &m);
23         memset(a, 0, sizeof a);
24         memset(up, 0, sizeof up);
25         memset(lx, 0, sizeof lx);
26         memset(rx, 0, sizeof rx);
27         for (int i = 1; i <= n; i++)
28             for (int j = 1; j <= m; j++){
29                 char op[10];
30                 scanf("%s", op);
31                 if (op[0] == 'F')a[i][j] = 1;
32                 else a[i][j] = 0;
33             }
34         int ans = 0;
35         for (int i = 0; i <= n; i++){
36             for (int j = 0; j <= m; j++){
37                 if(i==0)lf[j] = 1;
38                 if (!a[i][j])lx[j] = j;
39                 else lx[j] = lx[j - 1];
40             }
41             for (int j = m+1; j >= 1; j--){
42                 if(i==0)ri[j] = m;
43                 if (!a[i][j])rx[j] = j;
44                 else rx[j] = rx[j + 1];
45             }
46             for (int j = 1; j <= m; j++)
47                 if (a[i][j]){
48                     up[j] = up[j] + 1;
49                     lf[j] = max(lf[j], lx[j] + 1);
50                     ri[j] = min(ri[j], rx[j] - 1);
51                     ans = max(ans, (ri[j] - lf[j] + 1)*up[j]);
52                 }
53                 else lf[j] = 1, ri[j] = m, up[j] = 0;
54         }
55         printf("%d\n", ans*3);
56     }
57 }
View Code
posted @ 2013-12-24 19:28  HaibaraAi  阅读(110)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3