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 ...
随机推荐
- 编写更好的CSS
编写好的CSS代码能提升页面的渲染速度.本质上,一条规则都没有引擎解析的最快.MDN上将CSS选择符归拆分成四个主要类别,如下所示,性能依次降低. ID 规则 Class 规则 标签规则 通用规则 对 ...
- oracle impdp的table_exists_action详解
oracle impdp的table_exists_action详解 分类: [oracle]--[备份与恢复]2012-01-06 22:44 9105人阅读 评论(0) 收藏 举报 tableac ...
- HDU 3833 YY's new problem(换种思路的模拟,防超时)
题目链接 用p[a]保存的是输入的a在第p[a]个, 然后根据差值查找. #include<stdio.h> #include<string.h> int main() { ...
- WAMP error: Forbidden You don't have permission to access /{you_app_name} on this server
Forbidden You don't have permission to access /{you_app_name}on this server. 需要修改两处: wamp\bin\apache ...
- 2014多校第七场1005 || HDU 4939 Stupid Tower Defense (DP)
题目链接 题意 :长度n单位,从头走到尾,经过每个单位长度需要花费t秒,有三种塔: 红塔 :经过该塔所在单位时,每秒会受到x点伤害. 绿塔 : 经过该塔所在单位之后的每个单位长度时每秒都会经受y点伤害 ...
- Codeforces Round #336 (Div. 2) A. Saitama Destroys Hotel 模拟
A. Saitama Destroys Hotel Saitama accidentally destroyed a hotel again. To repay the hotel company ...
- ssh超时断开的解决方法
当用SSH Secure Shell连接Linux时,如果几分钟没有任何操作,连接就会断开,必须重新登陆才行,每次都重复相同的操作,很是烦人,本文总结了两种解决的方法. 方法1:更改ssh服务器的配置 ...
- lintcode:最小差
最小差 给定两个整数数组(第一个是数组 A,第二个是数组 B),在数组 A 中取 A[i],数组 B 中取 B[j],A[i] 和 B[j]两者的差越小越好(|A[i] - B[j]|).返回最小差. ...
- JavaScript的基础语法,你真的了解吗?
这篇文章是在我们熟悉了JS的基础语法后,很少有人去关注的一些细节部分.如果掌握了某些细节也许会对代码的改善有着非凡的作用.也许会使我们的代码更严谨,更高效. 1.if语句的条件 if条件中,括号里是布 ...
- mq_unlink
NAME mq_unlink - 销毁一个消息队列 (REALTIME) SYNOPSIS #include <mqueue.h> int mq_unlink(const char *na ...