Hdu-5024 Wang Xifeng's Little Plot(记忆化搜索)

从VMFL023案例看Fluent后处理:如何正确计算Strouhal数并避开‘采样间隔跳变’警告 本文以VMFL023案例为例,详细解析Fluent后处理中计算Strouhal数的正确方法,重点解决‘采样间隔跳变’警告问题。通过分析圆柱绕流物理特性、数据采样设置及FFT频谱分析技巧,帮助用户准确获取涡脱频率,提升CFD仿真结果的可信度。 阅读详情

Wang Xifeng's Little Plot

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 71    Accepted Submission(s): 49


Problem Description
《Dream of the Red Chamber》(also 《The Story of the Stone》) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel was created in Qing Dynasty, by Cao Xueqin. But the last 40 chapters of the original version is missing, and that part of current version was written by Gao E. There is a heart breaking story saying that after Cao Xueqin died, Cao's wife burned the last 40 chapter manuscript for heating because she was desperately poor. This story was proved a rumor a couple of days ago because someone found several pages of the original last 40 chapters written by Cao. 

In the novel, Wang Xifeng was in charge of Da Guan Yuan, where people of Jia family lived. It was mentioned in the newly recovered pages that Wang Xifeng used to arrange rooms for Jia Baoyu, Lin Daiyu, Xue Baochai and other teenagers. Because Jia Baoyu was the most important inheritor of Jia family, and Xue Baochai was beautiful and very capable , Wang Xifeng didn't want Jia Baoyu to marry Xue Baochai, in case that Xue Baochai might take her place. So, Wang Xifeng wanted Baoyu's room and Baochai's room to be located at two ends of a road, and this road should be as long as possible. But Baoyu was very bad at directions, and he demanded that there could be at most one turn along the road from his room to Baochai's room, and if there was a turn, that turn must be ninety degree. There is a map of Da Guan Yuan in the novel, and redists (In China English, one whose job is studying 《Dream of the Red Chamber》is call a "redist") are always arguing about the location of Baoyu's room and Baochai's room. Now you can solve this big problem and then become a great redist.
 

Input
The map of Da Guan Yuan is represented by a matrix of characters '.' and '#'. A '.' stands for a part of road, and a '#' stands for other things which one cannot step onto. When standing on a '.', one can go to adjacent '.'s through 8 directions: north, north-west, west, south-west, south, south-east,east and north-east.

There are several test cases.

For each case, the first line is an integer N(0<N<=100) ,meaning the map is a N × N matrix.

Then the N × N matrix follows.

The input ends with N = 0.
 

Output
For each test case, print the maximum length of the road which Wang Xifeng could find to locate Baoyu and Baochai's rooms. A road's length is the number of '.'s it includes. It's guaranteed that for any test case, the maximum length is at least 2.
 

Sample Input
3 #.# ##. ..# 3 ... ##. ..# 3 ... ### ..# 3 ... ##. ... 0
 

Sample Output
3 4 3 5


题目大意:
在一个n*n的平面上'#'表示障碍物,'.'表示道路。
问,是否存在一点到另一点的路径的最长距离n。
这条路径满足,每个点可以朝8个方向前进,至多拐弯一次,而且只能拐90度的。

解析:记忆化搜索,对于每个'.'节点,搜索8个方向,记录下该方向,最远的距离,最后遍历每个'.'节点,求出所有节点所有90度的值最大值。最大值-1 就是最终结果(因为两段的起点被重复计算了一遍)。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 105;
const int INF = 0x3f3f3f3f;
const int dr[] = {-1,-1,-1, 0, 1, 1, 1, 0};
const int dc[] = {-1, 0, 1, 1, 1, 0,-1,-1};
struct Node {
	int step[8]; //记忆化搜索8个方向
}p[N][N];
char grid[N][N];
int n;
void solve(int r,int c) {
	int x,y;
	for(int d = 0; d < 8; d++) {
		x = r;
		y = c;
		while(x >= 0 && x < n && y >= 0 && y < n && grid[x][y] != '#') {
			p[r][c].step[d]++;
			x += dr[d];
			y += dc[d];
		}
	}
}
int main() {
	while(scanf("%d",&n) != EOF && n) {
		memset(p,0,sizeof(p));
		for(int i = 0; i < n; i++) {
			scanf("%s",grid[i]);
		}
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(grid[i][j] == '#') {
					continue;
				}
				solve(i,j);
			}
		}
		int maxn = -INF;
		int sum,d;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(grid[i][j] == '#') {
					continue;
				}
				for(int k = 0; k < 8; k++) {
					d = (k+6) % 8; //当前方向左边
					sum = p[i][j].step[k] + p[i][j].step[d];
					maxn = max(maxn,sum);
					d = (k+2) % 8; //当前方向右边
					sum = p[i][j].step[k] + p[i][j].step[d];
					maxn = max(maxn,sum);
				}
			}
		}
		printf("%d\n",maxn-1);
	}
	return 0;
}

HSPICE用户必看:用Sigrity Broadband SPICE解决复杂封装建模的3个技巧 本文为HSPICE用户分享了三个使用Sigrity Broadband SPICE解决复杂封装建模难题的实战技巧。通过将宽频带S参数高效转换为时域SPICE模型,能显著提升仿真速度、保障收敛性,并精准分析谐振、返回路径不连续及超多端口PDN等关键问题,助力实现高效稳定的系统级信号与电源完整性分析。 阅读详情

相关推荐

k-shape时间序列聚类实战:从理论到tslearn实现

本文深入探讨了k-shape时间序列聚类算法,从核心原理到tslearn库的实战应用。k-shape通过标准化互相关系数衡量序列形状相似性,专注于识别波动模式而非绝对数值。文章详细介绍了算法流程、Python环境搭建、数据预处理、最佳K值确定方法,并通过完整代码示例展示了模型训练与结果可视化,帮助读者掌握这一强大的“形状捕手”工具。

weixin_29061465的博客 175

HDU 5024

题目传送门 http://acm.hdu.edu.cn/showproblem.php?pid=5024 题目大意就是给你一个存在障碍的地图,每次只能旋转90度仅且一次,要你求出最长的通路 其实是一道暴力的水题,哎一开始想着很SB的方法,写了大半天都没写出来,看了看别人的枚举思路后就瞬间茅塞顿开了~~,就是以每个点为转折点,算出齐八个方向转折线路的最大和,然后每个点比较就出现最大值啦>...

weixin_30753873的博客 88

基于深度学习的柠檬等级检测系统 —— YOLOv8 + UI界面 + 数据集

本项目的目标是构建一个柠檬等级检测系统,通过深度学习模型自动检测柠檬的等级。自动检测柠檬等级:通过图像中的柠檬特征,自动判断其成熟度和质量。实时视频检测:通过摄像头实时监控柠檬的质量等级。用户友好的UI界面:为用户提供简洁直观的操作界面,支持图像上传、实时视频检测等功能。本项目展示了如何基于YOLOv8模型开发一个柠檬等级检测系统,结合PyQt5实现了用户友好的UI界面。通过该系统,用户可以快速上传柠檬图像并自动识别其等级,极大提升了检测效率和准确性。数据集的扩展。

YOLO 1112

HDU 5024 Wang Xifeng's Little Plot(暴力枚举+瞎搞)

HDU 5024 Wang Xifeng's Little Plot(暴力枚举+瞎搞)

1655

2025年CSP-J复赛真题及题解:T4 多边形(polygon)

2025年CSP-J复赛真题及题解:T4 多边形(polygon)

王老师青少年编程 1718

如何免费快速的部署一个自用免VIP的自动追剧工具!NAS新玩法!豆瓣与迅雷结合,轻松实现自动下载电影自动追剧功能(支持Windows,群晖nas,飞牛nas,软路由,服务器等Docker快速部署)

追剧党狂喜!豆瓣追剧神器,自动添加云盘,自动下载,微信通知,一键搞定!

XiaoqiangClub的博客 4584

HDU 5024 Wang Xifeng's Little Plot (bfs)

Problem Description 《Dream of the Red Chamber》(also 《The Story of the Stone》) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel

左眼皮跳跳 1750

QGIS004:【05矢量属性表】-保留字段、删除字段、添加唯一值索引字段、添加字段到属性表、添加自增量字段、添加XY字段到图层、文本型转浮点型、重构字段、重命名字段

摘要:QGIS矢量属性表工具箱包括保留字段、删除字段、添加唯一值索引字段、添加字段到属性表、添加自增量字段、添加XY字段到图层、文本型转浮点型、重构字段、重命名字段等选项,本文介绍各选项的基本操作。

qq_31762031的博客 2312

HDU 5024 - Wang Xifeng's Little Plot(模拟)

Wang Xifeng’s Little PlotTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1122 Accepted Submission(s): 647Problem Description 《Dream of the

Snakeflute的博客 513

【软件系统架构】系列四:嵌入式软件-NPU(神经网络处理器)系统及模板

NPU(Neural Processing Unit) 是专门用于人工神经网络推理与训练的处理器,具备高并行、低功耗、低延迟等特点。它是边缘 AI、自动驾驶、智能摄像头、语音识别等场景中的关键硬件。

moton2017的博客 2251

Qt | linux+openCV+Qt6.5.3环境搭建成功版(带例子)

opencv安装 Qt 实战举例

Qt历险记,专注Qt技术,三年医疗设备研发经验,1年机器视觉研发经验,半年柔性传感研发经验。 1885

hdu5024

思路要开阔些,或者说要转化一下思路,别太死 把每个点当拐点,爆一边就可以,用记忆化搜索也行。都不会超时 #include using namespace std; int n; #define o ans=max(ans, char C[105][105]; int f(int i,int j,int a,int b){ int k=0; while(1){

Dosth_Magic 739

海洋CMS admin_notify.php 远程代码执行漏洞复现(CVE-2024-30565)

海洋CMS admin_notify.php 接口处存在远程代码执行漏洞,经过身份验证的远程攻击者可利用该漏洞执行任意代码,写入后门文件,进而控制整个web服务器。

0xSec 2715

HDU5024 Wang Xifeng's Little Plot 【记忆化搜索】

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 319    Accepted Submission(s): 214 Problem Description 《D

长风的专栏 1322

SAP B1中文培訓教材_SDK

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

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

hdu5024 Wang Xifeng's Little Plot记忆化搜索

传送门:hdu5024 题意:求从图中任意一点出发的最长路(只能拐一次弯) 一开始自己写的枚举每个点然后TLE,看了题解才发现自己思维太僵化了。。应该枚举拐点,枚举每个点的两两成直角的方向。这其中又加入了一个记忆数组dp[i][j][dir],用来记录i,j点在dir方向最多能走多远,直接将时间优化到0ms。。 #include #include #include #include

WA是一笔财富 347

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

HDU5024Wang Xifeng's Little Plot(记忆化搜索)

HDU5024Wang Xifeng's Little Plot(记忆化搜索) 题目链接 题目大意:给一张地图,#代表不能走的位置,.代表可以走的位置。现在要求找一条最长的路径,并且拐弯最多只能有一个并且还要是90度的。 解题思路:记忆化搜索,dp[x][y][k][d] : x, y 代表坐标,k代表拐了k次90弯,d代表方向。因为这里最多只能转一次弯,而且还必须是90度的,那

900

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

HDU 5024 Wang Xifeng's Little Plot 记忆化搜索

题意:给出一个迷宫,让你

leodestiny 555

HDU 5024 (广州网络赛) Wang Xifeng's Little Plot 记忆化搜索+枚举

Problem Description 《Dream of the Red Chamber》(also 《The Story of the Stone》) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel

旧时光 1080

HDU 5024 Wang Xifeng's Little Plot (枚举 + DFS记忆化搜索)

HDU 5024 Wang Xifeng's Little Plot (枚举 + DFS记忆化搜索)

Tc的专栏 1201

HDU - 5024 Wang Xifeng's Little Plot

Problem Description 《Dream of the Red Chamber》(also 《The Story of the Stone》) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel

那些年 1496

HDU 5024 Wang Xifeng's Little Plot(广州网络赛C题)

HDU 5024 Wang Xifeng's Little Plot 题目链接 思路:先利用记忆化搜索预处理出每个结点对应8个方向最远能走多远,然后枚举拐点记录最大值即可 代码: #include #include #include using namespace std; const int d[8][2] = {{-1, 0}, {0, 1}, {1, 0},

Remilia's 890

hdu 5024 Wang Xifeng's Little Plot【暴力dfs,剪枝】

2014年广州网络赛的C题,也是水题。要你在一个地图中找出一条最长的路,这条路要保证最多只能有一个拐角,且只能为90度 我们直接用深搜,枚举每个起点,每个方向进行dfs,再加上剪枝。 但是如果直接写的话,那一定会特别麻烦,再加上方向这一属性也是我们需要考虑的方面,我们将从别的地方到当前点的方向编一个号:往右为0,如下图顺时针顺序编号 (往右下方向为1,往下为2......以此

... 1008

HDU 5024 Wang Xifeng's Little Plot 暴搜

题目描述:Problem Description 《Dream of the Red Chamber》(also 《The Story of the Stone》) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This no

喵头鹰的博客 507

HDU 5025 Wang Xifeng's Little Plot(DFS)

Wang Xifeng's Little Plot#include &lt;iostream&gt; #include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;algorithm&gt; using namespace std; const int MAXN = 100+10; int n,ans; char map[MAXN][...

ccshijtgc的专栏 196

HDU5024

Problem Description 《Dream of the Red Chamber》(also 《The Story of the Stone》) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel w

NineFailure的博客 453

2014广州网络赛 Wang Xifeng's Little Plot

很多人都是用记忆话搜索或者bfs

中华鲁迅的专栏 1053
上一篇: UVA - 311 Packets(贪心)
下一篇: NYOJ 14 会场安排问题(选择不相交区间)
HelloWorld10086
博客等级 码龄12年 88粉丝 614原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值