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

悬线法典型例题。

//up[i][j]表示矩形高度为up[i][j]  left[i][j]表示最左边能到坐标left[i][j]  right[i][j]表示最右边能到坐标right[i][j]

转移即可,注意细节

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
inline void swap(int &a, int &b)
{
int tmp = a;a = b;b = tmp;
}
inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '') c = ch, ch = getchar();
while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
if(c == '-') x = -x;
} const int INF = 0x3f3f3f3f;
const int MAXN = + ; int t,n,m,left[MAXN][MAXN],right[MAXN][MAXN],up[MAXN][MAXN],ans;
char s[MAXN][MAXN];
//up[i][j]表示矩形高度为up[i][j] left[i][j]表示最左边能到坐标left[i][j] right[i][j]表示最右边能到坐标right[i][j] int main()
{
read(t);
for(;t;--t)
{
read(n), read(m);
for(register int i = ;i <= n;++ i) for(register int j = ;j <= m;++ j) scanf("%s", &s[i][j]);
ans = ;
for(register int i = ;i <= n;++ i)
{
//左->右维护up和left
int lo = ;
for(register int j = ;j <= m;++ j)
{
if(s[i][j] == 'R') left[i][j] = up[i][j] = , lo = j;
else
{
left[i][j] = max(left[i - ][j], lo + );
up[i][j] = up[i - ][j] + ;
}
}
int ro = m + ;
for(register int j = m;j >= ;-- j)
{
if(s[i][j] == 'R') right[i][j] = n + , ro = j;
else right[i][j] = i == ? ro - : min(right[i - ][j], ro - );
ans = max(ans, (right[i][j] - left[i][j] + ) * up[i][j]);
}
}
printf("%d\n", ans * );
}
return ;
}

LA3029

LA3029 City Game的更多相关文章

  1. BZOJ 2001: [Hnoi2010]City 城市建设

    2001: [Hnoi2010]City 城市建设 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 1132  Solved: 555[Submit][ ...

  2. History lives on in this distinguished Polish city II 2017/1/5

    原文 Some fresh air After your time underground,you can return to ground level or maybe even a little ...

  3. History lives on in this distinguished Polish city 2017/1/4

    原文 History lives on in this distinguished Polish city Though it may be ancient. KraKow, Poland, is a ...

  4. #1094 : Lost in the City

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He does not know where he is ...

  5. GeoIP Legacy City数据库安装说明

    Here is a brief outline of the steps needed to install GeoIP Legacy City on Linux/Unix. The installa ...

  6. [POJ3277]City Horizon

    [POJ3277]City Horizon 试题描述 Farmer John has taken his cows on a trip to the city! As the sun sets, th ...

  7. 2015年第8本(英文第7本):the city of ember 微光城市

    书名:the City of Ember(中文名:微光城市) 作者:Jeanne DuPrau 单词数:6.2万 不重复单词数:未知 首万词不重复单词数:未知 蓝思值:未知 阅读时间:2015年4月2 ...

  8. 离散化+线段树 POJ 3277 City Horizon

    POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 507 ...

  9. HDU 1505 City Game (hdu1506 dp二维加强版)

    F - City Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

随机推荐

  1. 6_3.springboot2.x数据整合Mybatis(注解和非注解)

    1.配置文件 pom.xml 导入mybatis提供的启动器 <dependency> <groupId>org.mybatis.spring.boot</groupId ...

  2. c# Data = select new{} 返回值的显示

  3. CSRF spring mvc 跨站请求伪造防御(转)

    CSRF CSRF(Cross-site request forgery跨站请求伪造,也被称为“One Click Attack”或者Session Riding,通常缩写为CSRF或者XSRF,是一 ...

  4. Linux 下 Nand Flash 驱动主要数据结构说明

    s3c2410 专有数据结构 s3c2410_nand_set struct s3c2410_nand_set { int                    nr_chips;     /* 芯片 ...

  5. Codeforces Round #479 (Div. 3) 题解 977A 977B 977C 977D 977E 977F

    A. Wrong Subtraction 题目大意:   定义一种运算,让你去模拟 题解:   模拟 #include <iostream> #include <cstdio> ...

  6. 2016.10.4初中部下午NOIP普及组比赛总结

    2016.10.4初中部下午NOIP普及组比赛总结 这次的题有些水,只是第四题有点坑. 题目: 比赛:AC+0+AC+50=250 改题:AC+AC+AC+50=350 一.Bill 满地都是水 题目 ...

  7. css之height: 100%的有效场景

    在css的日常应用中,经常会遇到想要通过 height: 100%来达到使子盒子与父盒子高度一样的目的,但是偶尔明明设置了height: 100%,但是却没有达到想要的结果,这次我们就一起探索一下,什 ...

  8. 传递闭包+求概率——列项相消法lightoj1321好题

    主要是要想到边与边的通过概率是独立的,所以先求出最终的概率,然后用推出的公式求总期望即可 最终概率E[0][n-1],可以用传递闭包来做 裂项相消法都不会了.. /* 闭包上推期望 每条边都具有独立性 ...

  9. iscroll 上拉加载和下拉刷新

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...

  10. Docker系列(十二):Kubernetes的分布式网络实践

    tip:本节课的学习视频没有找到,所以有的地方可能不是很清晰. 可选的几种网络方案 openvswitch 是一种主流的虚拟化大二层技术 灵活 对现有物理网络没要求 业界主流 软件封装导致性能低 复杂 ...