这题是上一题的升级版

关键在于条形图的构造,逐行处理输入的矩阵,遇到'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的更多相关文章

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

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

  2. HDU 1505 City Game(01矩阵 dp)

    Problem Description Bob is a strategy game programming specialist. In his new city building game the ...

  3. HDU 1505 City Game(DP)

    City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  4. hdu 1505 City Game (hdu1506加强版)

    # include <stdio.h> # include <algorithm> # include <string.h> # include <iostr ...

  5. HDU 1505 City Game【DP】

    题意:是二维的1506,即在1506的基础上,再加一个for循环,即从第一行到最后一行再扫一遍--- 自己写的时候,输入的方法不对---发现输不出结果,后来看了别人的----@_@发现是将字母和空格当 ...

  6. HDU 1505 Largest Rectangle in a Histogram &amp;&amp; HDU 1506 City Game(动态规划)

    1506意甲冠军:给你一个连续的直方图(拼贴底部长度1).求连续基质区. 对每一个直方图,分别向左向右进行扩展. #include<cstdio> #include<stdlib.h ...

  7. POJ 1964&HDU 1505&HOJ 1644 City Game(最大0,1子矩阵和总结)

    最大01子矩阵和,就是一个矩阵的元素不是0就是1,然后求最大的子矩阵,子矩阵里的元素都是相同的. 这个题目,三个oj有不同的要求,hoj的要求是5s,poj是3秒,hdu是1秒.不同的要求就对应不同的 ...

  8. HDU 3634 City Planning (离散化)

    City Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  9. hdu 3624 City Planning(暴力,也可扫描线)

    City Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

随机推荐

  1. Maven在项目中的应用

    http://192.168.0.253:8081/nexus/#view-repositories;thirdparty~uploadPanel 使用局域网搭建的环境,输入用户名和密码登录,上传ja ...

  2. oracle impdp的table_exists_action详解

    oracle impdp的table_exists_action详解 分类: [oracle]--[备份与恢复]2012-01-06 22:44 9105人阅读 评论(0) 收藏 举报 tableac ...

  3. POJ 2785

    4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 14475   Accep ...

  4. jquery select处理

    JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转.传参 js 处理 select :选中,删除,更改等 http://blog.csdn.net/wust_star/ ...

  5. JDBC资料集

    1.基本的JDBC概念: http://dev.mysql.com/doc/refman/5.1/zh/connectors.html#cj-basic-jdbc 2.JSP&Servlet学 ...

  6. CentOS 6.5下安装Zabbix 2.2.x

    操作系统:CentOS Mini 6.5 yum install httpd.x86_64 httpd-manual.x86_64 php-xml  php-mbstring mysql-server ...

  7. 【hdu2815-Mod Tree】高次同余方程-拓展BadyStepGaintStep

    http://acm.hdu.edu.cn/showproblem.php?pid=2815 题意:裸题... 关于拓展BSGS的详细解释我写了一篇博文:http://www.cnblogs.com/ ...

  8. lintcode:买卖股票的最佳时机 III

    买卖股票的最佳时机 III 假设你有一个数组,它的第i个元素是一支给定的股票在第i天的价格.设计一个算法来找到最大的利润.你最多可以完成两笔交易. 样例 给出一个样例数组 [4,4,6,1,1,4,2 ...

  9. Java多线程-线程的调度(休眠)

    Java线程调度是Java多线程的核心,只有良好的调度,才能充分发挥系统的性能,提高程序的执行效率. 这里要明确的一点,不管程序员怎么编写调度,只能最大限度的影响线程执行的次序,而不能做到精准控制. ...

  10. Java学习笔记之:Java Map集合

    一.介绍 通常来说,Map是一个由键值对组成的数据结构,且在集合中每个键是唯一的. 二.笔记 /** * Map:接口. 不是collection的子类 key -value 键值对 key唯一不能重 ...