LA3029 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
悬线法典型例题。
//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的更多相关文章
- BZOJ 2001: [Hnoi2010]City 城市建设
2001: [Hnoi2010]City 城市建设 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 1132 Solved: 555[Submit][ ...
- 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 ...
- 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 ...
- #1094 : Lost in the City
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He does not know where he is ...
- GeoIP Legacy City数据库安装说明
Here is a brief outline of the steps needed to install GeoIP Legacy City on Linux/Unix. The installa ...
- [POJ3277]City Horizon
[POJ3277]City Horizon 试题描述 Farmer John has taken his cows on a trip to the city! As the sun sets, th ...
- 2015年第8本(英文第7本):the city of ember 微光城市
书名:the City of Ember(中文名:微光城市) 作者:Jeanne DuPrau 单词数:6.2万 不重复单词数:未知 首万词不重复单词数:未知 蓝思值:未知 阅读时间:2015年4月2 ...
- 离散化+线段树 POJ 3277 City Horizon
POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 507 ...
- HDU 1505 City Game (hdu1506 dp二维加强版)
F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
随机推荐
- 基于jdk8的格式化时间方法
背景 jdk8之前,java使用Date表示时间,在做时间的格式化时,通常使用SimpleDateFormat,但是SimpleDateFormat是非线程安全的,在写代码时通常要将之定义为局部变量或 ...
- iOS开发系列-NSOperation
概述 NSOperation是基于GCD的封装更加面向对象,在使用上也是有任务跟队列的概念,分别对应两个类NSOperation .NSOperationQueue NSOperation和NSOpe ...
- asp.net去除HTML标签
public string NoHTML(string Htmlstring) //替换HTML标记 { //删除脚本 Htmlstring = Regex.Replace(Htmlstring, @ ...
- [NOIP2019模拟赛]数数(gcd)
题目大意: 求l~r中有多少数与x互质,带单点修改 分析: 两个30的部分分很好打: ·n<=1000暴力O(nq)就好了 ·$a_i<=100$用树状数组维护每个x的前缀和就好了 100 ...
- 【案例】鼠标按下,DIV跟随移动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- HTML值改变事件
1.动态拼接html[表格中,如bootstrap grid] return '<input type="text" name="bjce" onchan ...
- Windows安全证书生成方法(开发者证书)
首先,查看本机安装的证书可在“运行”中输入:certmgr.msc 一.win8.8.1.win10系统,使用管理员powershell创建证书: (1)利用如下命令来创建证书并获取到其指纹 New- ...
- IoC深入理解
1. IoC理论的背景 我们都知道,在采用面向对象方法设计的软件系统中,它的底层实现都是由N个对象组成的,所有的对象通过彼此的合作,最终实现系统的业务逻辑. 图1:软件系统中耦合的对象 如果我们打开机 ...
- Java学习之二(线程(了解) JVM GC 垃圾回收)
线程与进程(了解)→JVM→字节码→GC 一.程序 = 算法 + 数据结构(大佬) 二.程序 = 框架 + 业务逻辑(现实) 1.线程与进程.同步与异步 1.1进程是什么? 进程就是操作系统控制的基本 ...
- vue表格之:formatter=fun
作用:对从数据库中取出的数据进行处理后展示. 示例1: partner1为从数据库中查询出的展示字段,值为数字id,需要转化成中文名称 partners为全量查询结果,包含了id与中文名称的一一对应关 ...