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 ...
随机推荐
- 微信连WiFi关注公众号流程更新 解决ios微信扫描二维码不关注就能上网的问题
前几天鼓捣了一下微信连WiFi功能,设置还蛮简单的,但ytkah发现如果是ios版微信扫描微信连WiFi生成的二维码不用关注公众号就可以直接上网了,而安卓版需要关注公众号才能上网,这样就少了很多ios ...
- HDU 4937 Lucky Number (数学,进制转换)
题目 参考自博客:http://blog.csdn.net/a601025382s/article/details/38517783 //string &replace(iterator fi ...
- C#中反射泛型 CreateInstance
假设1我有个类叫SortClass,类中有个BubbleSort(int[] array)用于给数组进行排序. 假设2我有个类叫SortT<T>,类中有个BubbleSort(T[] ar ...
- HDU 1016 Prime Ring Problem (素数筛+DFS)
题目链接 题意 : 就是把n个数安排在环上,要求每两个相邻的数之和一定是素数,第一个数一定是1.输出所有可能的排列. 思路 : 先打个素数表.然后循环去搜..... #include <cstd ...
- hdu 4352 XHXJ's LIS 数位DP
数位DP!dp[i][j][k]:第i位数,状态为j,长度为k 代码如下: #include<iostream> #include<stdio.h> #include<a ...
- hdu 4112 Break the Chocolate(ceil floor)
规律题: #include<stdio.h> #include<math.h> #define eps 1e-8 int main() { int _case; int n,m ...
- 多线程包:java.util.concurrent,
Java1.5提供了一个非常高效实用的多线程包:java.util.concurrent,
- iOS xcode缓存问题
Question: When I try to build my app in Xcode, I get this error message:PCH file built from a differ ...
- ActiveMQ简单的HelloWorld实例
我们使用ActiveMQ为大家实现一种点对点的消息模型. 开发时候,要将apache-activemq-5.12.0-bin.zip解压缩后里面的activemq-all-5.12.0.jar包加入到 ...
- PowerDesigner如何自定义报表模板
PowerDesigner如何自定义报表模板 帅宏军 使用PowerDesigner设计数据库非常方便,但是它自带的报表模板一般不符合中国的使用情况.如何设计一个自己的报表模板,并在做项目的数据库设计 ...