这题是上一题的升级版

关键在于条形图的构造,逐行处理输入的矩阵,遇到'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. HTTP报头详解

    HTTP头字段包括4类:      general-header ; 通用报头      request-header ; 请求报头      response-header ; 响应报头      ...

  2. linux 上传/下载文件到windows工具

    一般来说,linux服务器大多是通过ssh客户端来进行远程的登陆和管理的,使用ssh登陆linux主机以后,如何能够快速的和本地机器进行文件的交互呢,也就是上传和下载文件到服务器和本地:   与ssh ...

  3. 【基本算法】 KMP文本串模式串的字符串匹配算法

    看了两个晚上的KMP,加上基本的“暴力匹配” 今晚看懂next[j]递归求解时,突然觉得算法真的好美妙,虽然觉悟的晚但晚胜过没有是吧! 我的博客都是应试性的学习笔记,不具备指导性,还是大神们写的好,例 ...

  4. Oracle MySQL

    http://blog.jobbole.com/46510/ http://blackproof.iteye.com/blog/1570456 http://blog.csdn.net/yzsind/ ...

  5. ELk 几篇好的文章

    https://nxlog.co/docs/elasticsearch-kibana/using-nxlog-with-elasticsearch-and-kibana.html http://www ...

  6. poj 2425 A Chess Game 博弈论

    思路:SG函数应用!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include< ...

  7. 知问前端——对话框UI(一)

    对话框(dialog),是jQuery UI非常重要的一个功能.它彻底的代替了JavaScript的alert().prompt()等方法,也避免了新窗口或页面的繁杂冗余. 开启多个dialog 我们 ...

  8. 【poj1061-青蛙的约会】拓展欧几里得-不定方程

    http://poj.org/problem?id=1061 题意:裸题.注意负数. //poj1061 #include<cstdio> #include<cstdlib> ...

  9. http://www.cnblogs.com/leiOOlei/p/5075402.html

    http://www.cnblogs.com/leiOOlei/p/5075402.html

  10. servlet学习笔记三

    Servlet主要内容: 1)状态跟踪 一.状态跟踪 HTTP协议是无状态协议,即请求与请求之间没有任何关系,也就是不会记住任何数据. 但若想在请求间传递数据,怎么办?web里的三个基本容器对象可以解 ...