[HDU 1505 City Game] HDU1506加强版

hdu1505 City Game二维01矩阵求最大矩形周长 City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2837    Accepted Submission(s): 1142 Problem Description Bob is a strategy ga 阅读详情

题目链接  http://acm.hdu.edu.cn/showproblem.php?pid=1505

City Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5711    Accepted Submission(s): 2464


Problem Description
Bob is a strategy game programming specialist. In his new city building game the gaming environment is as follows: a city is built up by areas, in which there are streets, trees,factories and buildings. There is still some space in the area that is unoccupied. The strategic task of his game is to win as much rent money from these free spaces. To win rent money you must erect buildings, that can only be rectangular, as long and wide as you can. Bob is trying to find a way to build the biggest possible building in each area. But he comes across some problems – he is not allowed to destroy already existing buildings, trees, factories and streets in the area he is building in.

Each area has its width and length. The area is divided into a grid of equal square units.The rent paid for each unit on which you're building stands is 3$.

Your task is to help Bob solve this problem. The whole city is divided into K areas. Each one of the areas is rectangular and has a different grid size with its own length M and width N.The existing occupied units are marked with the symbol R. The unoccupied units are marked with the symbol F.
 

Input
The first line of the input contains an integer K – determining the number of datasets. Next lines contain the area descriptions. One description is defined in the following way: The first line contains two integers-area length M<=1000 and width N<=1000, separated by a blank space. The next M lines contain N symbols that mark the reserved or free grid units,separated by a blank space. The symbols used are:

R – reserved unit

F – free unit

In the end of each area description there is a separating line.
 

Output
For each data set in the input print on a separate line, on the standard output, the integer that represents the profit obtained by erecting the largest building in the area encoded by the data set.
 

Sample Input
  
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
 

Sample Output
  
45 0
 

Source
 

简单的dp吧。。稍微想一下就行了,处理一下它给的图,例如第一个样例可以处理成

011111
122222
000333
111444
222555
开一个数组dp[i][j],每一行遍历一次,若是F,就加上上一行的dp值,求出连续F的个数,若遇到R就归0

如下:

for (int i = 1; i <= n; i++)
{
	for (int j = 1; j <= m; j++)
	{
		if (map[i][j] == 'R')
		dp[i][j] = 0;
		else dp[i][j] = dp[i - 1][j] + 1;
	}
}
得出每一行的数列后,就可以发现这题和HDU1506一毛一样,只是1506求一行,这题要求多行并取最大值

HDU 1506 题解 http://blog.youkuaiyun.com/chenninggo/article/details/48080271

注意下输入,因为卡输入wa了几次,也算是学到了特殊的输入技巧

代码如下。。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int t;
int n, m;
char map[1010][1010], ch[5];
int dp[1010][1010], l[1010], r[1010];
int main()
{
//  freopen("input.txt", "r", stdin);
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; i++)            //这种输入法真的好好用。。
			for (int j = 1; j <= m; j++)
			{
				scanf("%s", ch);
				map[i][j] = ch[0];
			}
		memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= n; i++)         //处理一下原图
		{
			for (int j = 1; j <= m; j++)
			{
				if (map[i][j] == 'R')
					dp[i][j] = 0;
				else dp[i][j] = dp[i - 1][j] + 1;
			}
		}
		int ans = -1, mx, id;
		for (int i = 1; i <= n; i++)
		{
			memset(l, 0, sizeof(l));
			memset(r, 0, sizeof(r));
			l[1] = 1;
			r[m] = m;
			for (int j = 2; j <= m; j++)             //和1506一样的方法
			{
				id = j;
				while (id > 1 && dp[i][j] <= dp[i][id - 1])
					id = l[id - 1];
				l[j] = id;
			}
			for (int j = m - 1; j >= 1; j--)
			{
				id = j;
				while (id < m && dp[i][j] <= dp[i][id + 1])
					id = r[id + 1];
				r[j] = id;
			}
			mx = -1;
			for (int j = 1; j <= m; j++)
				mx = max(mx, (r[j] - l[j] + 1)*dp[i][j]);
			ans = max(mx, ans);
		}
		printf("%d\n", ans * 3);
	}
	return 0;
}






英飞凌TLF35584 SBC实战:手把手教你配置WDG看门狗与ERR监控(基于AUTOSAR架构) 本文详细介绍了基于AUTOSAR架构的英飞凌TLF35584 SBC芯片WDG看门狗与ERR监控功能的配置方法。通过硬件平台搭建、寄存器级配置、AUTOSAR模块集成及诊断策略优化,帮助开发者快速掌握关键配置技巧,提升嵌入式系统的安全性和可靠性。 阅读详情

相关推荐

手把手教你用示波器实测CAN总线波形:快速区分高速、低速及常见故障

本文详细介绍了如何使用示波器实测CAN总线波形,快速区分高速CAN总线和低速CAN总线,并诊断常见故障。通过实战案例和波形分析,帮助工程师掌握CAN总线信号特征,提升故障排查效率,适用于汽车电子和工业控制领域。

weixin_33217202的博客 410

poj_A Chess Game2425

A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3094   Accepted: 1266 Description Let's design a new chess game. There are N positions to hold M

u012631715的专栏 576

EGO-Planner文章解读(一)——论文原理和算法实现

详细解读egoplanner论文和代码

fegxg的博客 3989

HDU1505 City Game (DP,HDU1506加强版)

链接: http://acm.hdu.edu.cn/showproblem.php?pid=1505 没做过1506的建议先去做1506,我有详细解释 1506链接:http://blog.youkuaiyun.com/xtttgo/article/details/48085707 因为我是用1506的方法做的这题 题意:R是障碍物,求最大的F形成的矩形 实际上,我们把R的情况去掉,就是跟150

xtttgo的博客 387

Python爬虫实战:从巨潮网批量抓取上市公司年报JSON数据

网络爬虫作为自动化数据采集的核心技术,其原理是通过模拟浏览器行为向服务器发送HTTP请求并解析响应,从而高效获取结构化信息。在金融数据分析领域,这项技术价值尤为突出,能够将研究人员从繁琐的手工数据收集中解放出来,聚焦于更高阶的模型构建与价值挖掘。典型的应用场景包括上市公司财务研究、市场趋势分析和风险预警系统开发。本文以Python的requests库为核心工具,详细解析如何通过分析巨潮资讯网的JSON数据接口,构建一个稳定、高效的上市公司年报数据采集管道,并重点探讨了接口逆向、分页爬取、PDF文件下载等关键

weixin_42529366的博客 1236

分辨率太小 / Retina 模糊 / 全屏异常:一篇解决 VMware Fusion + Kali 显示问题(Xfce & GNOME 通用)

本文提供了在Mac(尤其是Retina屏)上运行Kali Linux时常见显示问题的完整解决方案。主要解决三类问题:分辨率太小、Retina屏模糊和全屏异常。核心思路是先安装open-vm-tools-desktop并重启,这是90%问题的根源。然后根据不同问题分别处理:调整DPI/Scale解决字体大小,避免双重缩放导致的模糊,以及通过窗口拉伸和重启解决全屏异常。文章还给出了针对Xfce和GNOME的最佳配置建议,并强调调试完成后应创建快照以便快速恢复。最后提供了速查表,方便用户快速参考关键步骤。

致力于分享在各类技术领域的学习与实践经验,涵盖编程、虚拟化、开源工具、网络安全等。 874

hdu1505—City Game(1506的加强版)

题目链接:传送门 City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7143    Accepted Submission(s): 3097 Problem Description

zhiyuanjiang的博客 302

别再乱调NvM_WriteBlock了!手把手教你搞懂Autosar NVM状态机与读写时序

本文深入解析Autosar NVM状态机与读写时序,帮助开发者避免常见错误。通过详细的状态机解读、最佳实践代码示例和异常处理策略,提升嵌入式系统中数据存储的可靠性。特别针对NvM_WriteBlock的调用逻辑和状态机机制进行实战讲解,解决工程师在实际开发中遇到的异步写入问题。

weixin_33701617的博客 344

hdu 1505 city game(1506加强版)dp

题目大意:        给你一个n*m的矩阵,里面包含F或者是R,现在问你,用F组成一个矩阵,最大面积是多少。       题目和1506很相似,都是一个求最大矩阵面积的问题。只不过1505稍微复杂了一下,用了一个二维的,并且需要对字符串进行处理。 题目分析:       首先对字符串进行处理分析,然后再对每行进行如1506的操作,最后求得最大值就行了,详见代码解析。#include #

Tsaryu的博客 464

OSG三维渲染引擎编程学习之一:“第一章:OSG介绍” 之 “1.1 OSG简介”

第一章:OSG介绍; 1.1 OSG简介。

LuckyHanMo的博客 3223

X书关键词协议搜索

【代码】X书关键词协议搜索。

Codeooo 博客 6377

hdu 1505 City Game (hdu1506加强版)

# include # include # include # include using namespace std; char a[1010][1010]; int dd[1010][1010];///宽度 int r[1010],l[1010]; int main() { int t,i,j,n,m,max1; while(~scanf("%d",&t)) {

苍竹林 682

MOS管的体二极管在LLC中的作用

MOSFET是一个三端器件(G、D、S),在N沟道MOSFET的结构中,源极和漏极之间的N型材料中自然形成了一个寄生的PN结,这个PN结就是体二极管(Body Diode),它是不可避免的器件结构。📌 对于N沟MOSFET:体二极管是从漏极 D 到源极 S 的正向导通二极管,方向为 D → S。MOS管的体二极管在LLC中并不是主功率通道,但却是实现软开关(ZVS)和能量过渡的关键“临时路径”。用得好,它是你的朋友;忽略它,电路就可能烧毁。

weixin_43199439的博客 699

hdu 1505 city game (1506 加强版)

#include<iostream> #include<cstdio> #include<cstring> using namespace std; char ss[33]; int b[1002][1002],qian[1002],hou[1002]; int main() { int i,j,n,m,t; sc...

weixin_30347335的博客 107

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

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

F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1505 Appoint description: Description Bob is a strategy game pr...

weixin_30486037的博客 130

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

HDU1505--City Game(动态规划)(1506加强版)

这道题和1506差不多,多加了一维,只要求出每个F点上面的F点个数,然后压到一行中,就和1506一样了。 #include #include #include #include #include #define maxn 1005 using namespace std; struct Map { char c[5]; int num; int left,right; }map

慕枫幕影的专栏 886

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

HDU-1505-City Game——算法笔记

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505 Problem Description: Bob is a strategy game programming specialist. In his new city building game the gaming environment is as follows: a city is b...

学而不思则忘 441

HDU-1505-City Game【dp】【思维】

HDU-1505-City Game

Linoy 1186

【DP】 hdu1505 City Game

City Game http://acm.hdu.edu.cn/showproblem.php?pid=1505 Problem Description Bob is a strategy game programming specialist. In his new city building game the gaming environment is as foll

Ted's 游乐园 2679

HDU 1505 City Game(DP求二维最大子矩阵)

City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5913    Accepted Submission(s): 2533 Problem Description Bob is a strategy ga

HHH的专栏 445

HDU 1505 City Game

自己学的太死了。 也用不上刚学的。 这个题就是 对于一行lai

Shimmer_的专栏 780

hdu1505 City Game(DP)

思路:HDU1506的加强版,只要把算出以i 行为底能达到的最到的最大高度,再扫描每一行,就转化为 HDU1506 的问题了 #include using namespace std; const int maxn = 1005; int a[maxn][maxn]; int l[maxn],r[maxn]; int main() { int T; scanf("%d",&T);

围巾的ACM博客 284

City Game HDU - 1505(单调栈)

City Game HDU - 1505题意:开发商在一块m*n的地皮上建楼房, 一直这块地有空地和已用地, 空地用F表示, 已用地用R表示, 每单位面积的地皮市值3$, 求出这整块地皮上价值最大的一块矩形地皮;HDU 1506 ...

Sirius_han的博客 276

HDU 1505 动态规划(DP) City Game

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505 分析; [HDU 1506的深化版]每输入一行,更新一次高度,就变成了1505题的问题了.[本题深化版HDU 2870] #include #include #include #include #include #include using namespace std; int

PWZER 876

hdu1506 1505 2870最大子矩形 DP

Largest Rectangle in a Histogram

hccz95的专栏 1049
上一篇: [HDU 1506 Largest Rectangle in a Histogram] ...类dp?...
下一篇: [HDU 2602 Bone Collector] 宇宙无敌入门01背包
chenningGo
博客等级 码龄11年 1粉丝 17原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值