HDU 1505 City Game
这题是上一题的升级版
关键在于条形图的构造,逐行处理输入的矩阵,遇到'F'则在上一次的条形图基础上再加1,遇到'R'则置为0
然后用上一题的算法,求每行对应条形图的最大矩阵的面积。
另外:本来是debug都不用就1A的节奏。可在输入数据上,一开始我用的是scanf读入字符 和 getchar跳过无效字符,在测试数据上是没有问题的,但一交上去就WA掉了。
看到别人的代码使用cin读入的。其实,如果输入数据不太大的话,cin还是比较放心好用的。
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = ;
char map[maxn][maxn];
int h[maxn], l[maxn], r[maxn]; int main(void)
{
#ifdef LOCAL
freopen("1505in.txt", "r", stdin);
#endif int T;
scanf("%d", &T);
while(T--)
{
int row, col;
scanf("%d%d", &row, &col);
getchar();
int i, j;
for(i = ; i <= row; ++i)
for(j = ; j <= col; ++j)
cin >> map[i][j]; memset(h, , sizeof(h));
l[] = , r[col] = col;
int t, ans = -;
for(i = ; i <= row; ++i)
{
for(j = ; j <= col; ++j)
if(map[i][j] == 'F')
++h[j];
else
h[j] = ; for(j = ; j <= col; ++j)
{
t = j;
while(t > && h[j] <= h[t-])
t = l[t-];
l[j] = t;
}
for(j = col-; j > ; --j)
{
t = j;
while(t < col && h[j] <= h[t+])
t = r[t+];
r[j] = t;
}
for(j = ; j <= col; ++j)
ans = max(ans, (r[j]-l[j]+)*h[j]);
}
printf("%d\n", ans * );
}
return ;
}
代码君
HDU 1505 City Game的更多相关文章
- HDU 1505 City Game (hdu1506 dp二维加强版)
F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 1505 City Game(01矩阵 dp)
Problem Description Bob is a strategy game programming specialist. In his new city building game the ...
- HDU 1505 City Game(DP)
City Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- hdu 1505 City Game (hdu1506加强版)
# include <stdio.h> # include <algorithm> # include <string.h> # include <iostr ...
- HDU 1505 City Game【DP】
题意:是二维的1506,即在1506的基础上,再加一个for循环,即从第一行到最后一行再扫一遍--- 自己写的时候,输入的方法不对---发现输不出结果,后来看了别人的----@_@发现是将字母和空格当 ...
- HDU 1505 Largest Rectangle in a Histogram && HDU 1506 City Game(动态规划)
1506意甲冠军:给你一个连续的直方图(拼贴底部长度1).求连续基质区. 对每一个直方图,分别向左向右进行扩展. #include<cstdio> #include<stdlib.h ...
- POJ 1964&HDU 1505&HOJ 1644 City Game(最大0,1子矩阵和总结)
最大01子矩阵和,就是一个矩阵的元素不是0就是1,然后求最大的子矩阵,子矩阵里的元素都是相同的. 这个题目,三个oj有不同的要求,hoj的要求是5s,poj是3秒,hdu是1秒.不同的要求就对应不同的 ...
- HDU 3634 City Planning (离散化)
City Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 3624 City Planning(暴力,也可扫描线)
City Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
随机推荐
- MySQL注入load_file常用路径
WINDOWS下: c:/boot.ini //查看系统版本 c:/windows/php.ini //php配置信息 c:/windows/my.ini //MYSQL配置文件,记录管理员登陆过的M ...
- Sql注入一种dump所有数据的方法
Select exp(~(select*from(select(concat(@:=0,(select count(*)from`information_schema`.columns where t ...
- leetcode single number系列
这个系列一共有三题,第一题是一组数里除了一个数出现一次之外,其他数都是成对出现,求这个数. 第二题是一组数里除了两个数出现一次外,其他数都是成对出现,求这两个数 第三题是一组数里除了一个数出现一次外, ...
- Runtime的用法
public class RuntimeTest { public static void main(String[] args) { Runtime run =Runtime.getRuntime( ...
- POJ 1222
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6196 Accepted: 40 ...
- 【leetcode】Contains Duplicate & Rectangle Area(easy)
Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your funct ...
- 概述Log4j简介
在强调可重用组件开发的今天,除了自己从头到尾开发一个可重用的日志操作类外,Apache为我们提供了一个强有力的日志操作包-Log4j. Log4j是Apache的一个开放源代码项目,通过使用Log4j ...
- poj 2975 Nim 博弈论
令ans=a1^a2^...^an,如果需要构造出异或值为0的数, 而且由于只能操作一堆石子,所以对于某堆石子ai,现在对于ans^ai,就是除了ai以外其他的石子 的异或值,如果ans^ai< ...
- Spring MVC 教程,快速入门,深入分析(转)
原文地址:http://elf8848.iteye.com/blog/875830/
- iphone 异常捕获处理
iphone 异常捕获处理 1 void UncaughtExceptionHandler(NSException *exception) { 2 NSArray *arr = [exception ...