HDU 1505 Largest Rectangle in a Histogram && HDU 1506 City Game(动态规划)
1506意甲冠军:给你一个连续的直方图(拼贴底部长度1)。求连续基质区。

对每一个直方图,分别向左向右进行扩展。
#include<cstdio>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include <queue>
#include <stack>
#include<algorithm>
#include<set>
using namespace std;
#define INF 1e8
#define eps 1e-8
#define LL long long
#define N 100010
#define mol 1000000007
int i,n,t;
LL a[N],l[N],r[N],Max;
int main()
{
while (scanf("%d",&n) && n)
{
for (i=1; i<=n; ++i) scanf("%I64d",&a[i]);
l[1]=1;
r[n]=n;
for(i=2;i<=n;i++)
{
t=i;
while(t>1&&a[i]<=a[t-1])//从左往右向左扩展
t=l[t-1];
l[i]=t;
}
for(i=n-1;i>=1;i--)
{
t=i;
while(t<n&&a[i]<=a[t+1])//从右往左向右扩展
t=r[t+1];
r[i]=t;
}
Max=0;
for (i=1; i<=n; ++i)
{
if ((r[i]-l[i]+1)*a[i]>Max)
Max=(r[i]-l[i]+1)*a[i];
}
printf("%I64d\n",Max);
}
return 0;
}
1505题意:求最大零(F)矩阵,1506加强版,把2维转换化成以每一行底,组成的最大面积
#include<cstdio>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include <queue>
#include <stack>
#include<algorithm>
#include<set>
using namespace std;
#define INF 1e8
#define eps 1e-8
#define LL long long
#define maxn 1001
#define mol 1000000007
int t,n,m,a[maxn][maxn],l[maxn][maxn],r[maxn][maxn];
char s[maxn];
int main()
{ scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
int i,j;
memset(a,0,sizeof(a));
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
scanf("%s",s);
if(s[0]=='F') a[i][j]=a[i-1][j]+1;
else a[i][j]=0;
}
}
//printf("\n");
int ans=0;
for(i=1;i<=n;i++)
{
int t;
l[i][1]=1;r[i][m]=m;
for(j=2;j<=m;j++)
{
t=j;
while(t>1&&a[i][j]<=a[i][t-1])
t=l[i][t-1];
l[i][j]=t;
}
for(j=m-1;j>0;j--)
{
t=j;
while(t<m&&a[i][j]<=a[i][t+1])
t=r[i][t+1];
r[i][j]=t;
}
for(j=1;j<=m;j++)
{
if(a[i][j]*(r[i][j]-l[i][j]+1)>ans)
ans=a[i][j]*(r[i][j]-l[i][j]+1);
}
}
printf("%d\n",ans*3);
}
return 0;
}
/*
2
5 6
R F F F F F
F F F F F F
R R R F F F
F F F F F F
F F F F F F 5 5
R R R R R
R R R R R
R R R R R
R R R R R
R R R R R
*/
版权声明:本文博主原创文章,博客,未经同意不得转载。
HDU 1505 Largest Rectangle in a Histogram && HDU 1506 City Game(动态规划)的更多相关文章
- HDU 1506 & 1505 - Largest Rectangle in a Histogram & City Game
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- 暑期训练狂刷系列——Hdu 3506 Largest Rectangle in a Histogram (单调栈)
题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1506 题目大意: 给出一个数列An,问以Ai为最小值的区间内有多少个元素? 解题思路: 手动模拟一个 ...
- hdu 1507 Largest Rectangle in a Histogram 动态规划计算最大面积
记录动态规划dpl,dpr,分辨记录i左面的比i大的,右面比i大的,然后(dpr[i]-dpl[i]+1)*h[i]得出长度 动态转移方程while(temp>1 && h[te ...
- uva 1506 Largest Rectangle in a Histogram
Largest Rectangle in a Histogram http://acm.hdu.edu.cn/showproblem.php?pid=1506 Time Limit: 2000/100 ...
- Largest Rectangle in a Histogram(附上几组测试数据)
Largest Rectangle in a Histogram http://acm.hdu.edu.cn/showproblem.php?pid=1506 Time Limit: 2000/100 ...
- HDU——T 1506 Largest Rectangle in a Histogram|| POJ——T 2559 Largest Rectangle in a Histogram
http://acm.hdu.edu.cn/showproblem.php?pid=1506 || http://poj.org/problem?id=2559 Time Limit: 2000/1 ...
- HDU 1506 Largest Rectangle in a Histogram (dp左右处理边界的矩形问题)
E - Largest Rectangle in a Histogram Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
- HDU 1506 Largest Rectangle in a Histogram set+二分
Largest Rectangle in a Histogram Problem Description: A histogram is a polygon composed of a sequenc ...
- hdu 1506 Largest Rectangle in a Histogram 构造
题目链接:HDU - 1506 A histogram is a polygon composed of a sequence of rectangles aligned at a common ba ...
随机推荐
- htc one x刷机记录
这几天有些空余时间都用来刷htc one x,来说说刷机的艰难史吧. 首先是利用百度云rom刷机,本来一直用小米系统,突然发现百度云也能够搞个,所以心血来潮要刷个百度云,先利用软件解锁,哪知道没细致看 ...
- 当执行游戏0xc000007b错误的解决方法
如图,这个错误使无数玩家烦恼. 出现这个错误,可能是硬件的问题,也可能是软件的问题.可是,因为硬件引起该问题的概率非常小,而且除了更换硬件之外没有更好的解决方法,因此本文将具体介绍怎样通过软件解决此问 ...
- 索尼 LT26I刷机包 X.I.D 增加官方风格 GF A3.9.4 各方面完美
ROM介 FX_GF_A系列是具有官方风格的.稳定的.流畅的.省电的.新功能体验的.最悦耳音效体验的ROM. FX_GF_A更新日志 ☆ GF_3.9.4 更新信息 ☆ 更新播放器 ☆ 更新adsp数 ...
- HDU4144:Bacon's Cipher
Problem Description Bacon's cipher or the Baconian cipher is a method of steganography (a method of ...
- Windows下一个AndroidStudio 正在使用Git(AndroidStudio工程GitHub关联)
前提条件 : 1. 设备 Git client 下载链接 2. 有着 GitHub 账号 (假设你已经有了一些git基础, 假设还一点都不会, 请去找其它加成学习) AndroidStudio项目公布 ...
- 重新想象 Windows 8 Store Apps (30) - 信息: 获取包信息, 系统信息, 硬件信息, PnP信息, 常用设备信息
原文:重新想象 Windows 8 Store Apps (30) - 信息: 获取包信息, 系统信息, 硬件信息, PnP信息, 常用设备信息 [源码下载] 重新想象 Windows 8 Store ...
- T-SQL基础(5) - 表表达式
1.派生表(derived table)select YEAR(orderdate) as orderyear, COUNT(distinct custid) as numcustsfrom Sale ...
- 局部敏感哈希(Locality-Sensitive Hashing, LSH)方法介绍
局部敏感哈希(Locality-Sensitive Hashing, LSH)方法介绍 本文主要介绍一种用于海量高维数据的近似近期邻高速查找技术--局部敏感哈希(Locality-Sensitive ...
- 打开 chm 帮助文件显示空白及解决方法
有个很奇葩的解决方法:把 chm 文件用压缩软件压缩,然后用压缩软打开此压缩包,直接双击压缩包里面的 chm 文件 这虽然解决了问题,但是这不科学…… 分析:直接打开压缩包里面的文件,压缩包的文件是临 ...
- 密码 hdu
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submission(s) ...