Tempter of the Bone

本文介绍了一种基于回溯算法的迷宫逃逸问题解决方法。通过分析迷宫布局及移动限制,利用深度优先搜索(DFS)寻找在限定时间内到达出口的路径。文章详细解释了如何通过奇偶性减枝来优化搜索过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze. 

The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him. 

Input

The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), which denote the sizes of the maze and the time at which the door will open, respectively. The next N lines give the maze layout, with each line containing M characters. A character is one of the following: 

'X': a block of wall, which the doggie cannot enter; 
'S': the start point of the doggie; 
'D': the Door; or 
'.': an empty block. 

The input is terminated with three 0's. This test case is not to be processed. 

Output

For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise. 

Sample Input

4 4 5
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0

Sample Output

NO
YES
/*
用到了回溯和减枝 
*/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>

using namespace std;

const int maxn = 10;
int vis[maxn][maxn];
char str[maxn][maxn];
int n, m, T, s_x, s_y, e_x, e_y;
bool flag;

int d[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};


bool check(int x, int y){
    if(x >= 0 && x < n && y >= 0 && y < m)    
		return true;
    else return false;
}


void DFS(int x, int y, int t){
	if (str[x][y] == 'D' && t == T){
		flag = true;
		return;
	}
	vis[x][y] = 1;
	// 奇偶减枝  
	int temp = T - t - (abs(x-e_x)+abs(y-e_y));
// 总时间 要求时间 已用时间 最短距离所用时间 
    if(temp < 0 || (temp & 1))  return;
//如果temp小于0证明当前时间无法到达 return
//如果temp为奇数是不可能的 return	
	for (int i = 0; i < 4; i++){
		int dx = x + d[i][0];
		int dy = y + d[i][1];
		if (check(dx, dy) && !vis[dx][dy] && str[dx][dy] != 'X'){
			DFS(dx, dy, t+1);
			//回溯
			if (flag) return; 
			vis[dx][dy] = 0;
		}
	}
}

int main()
{
	while (scanf ("%d %d %d", &n, &m, &T) != EOF && (n || m || T)){
		for (int i = 0; i < n; i++){
			scanf ("%s", str[i]);
		}
		
		memset(vis, 0, sizeof(vis));
		flag = false;
		
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++){
				if (str[i][j] == 'S')
					s_x = i, s_y = j;
				if (str[i][j] == 'D')
					e_x = i, e_y = j;
			}	
		DFS (s_x, s_y, 0);
		if (flag) printf ("YES\n");
		else printf ("NO\n");
	}
	return 0;
}
/*
把矩阵看成如下形式: 
0 1 0 1 0 1 
1 0 1 0 1 0 
0 1 0 1 0 1 
1 0 1 0 1 0 
0 1 0 1 0 1 
从为 0 的格子走一步,必然走向为 1 的格子 。
从为 1 的格子走一步,必然走向为 0 的格子 。
即: 
从 0 走向 1 必然是奇数步,从 0 走向 0 必然是偶数步。

所以当遇到从 0 走向 0 但是要求时间是奇数的或者
 从 1 走向 0 但是要求时间是偶数的,都可以直接判断不可达!
比如一张地图c

 

S...  
....  
....  
....  
...D  
要求从S点到达D点,此时,从S到D的最短距离为s = abs ( dx - sx ) + abs ( dy - sy )。

如果地图中出现了不能经过的障碍物:

S..X  
XX.X  
...X  
.XXX  
...D  
此时的最短距离s' = s + 4,为了绕开障碍,不管偏移几个点,偏移的距离都是最短距离s加上一个偶数距离。

就如同上面说的矩阵,要求你从0走到0,无论你怎么绕,永远都是最短距离(偶数步)加上某个偶数步;
要求你从1走到0,永远只能是最短距离(奇数步)加上某个偶数步。
 
*/

 

内容概要:该论文聚焦于6G通信中20-100GHz频段的电磁场(EMF)暴露评估问题,提出了一种基于自适应可重构架构神经网络(RAWA-NN)的预测框架。该框架通过集成权重分析模块和优化模块,能够自动优化网络超参数,显著减少训练时间。模型使用70%的前臂数据进行训练,其余数据用于测试,并用腹部和股四头肌数据验证模型泛化能力。结果显示,该模型在不同参数下的相对差异(RD)在前臂低于2.6%,其他身体部位低于9.5%,可有效预测皮肤表面的温升和吸收功率密度(APD)。此外,论文还提供了详细的代码实现,涵盖数据预处理、权重分析模块、自适应优化模块、RAWA-NN模型构建及训练评估等内容。 适合人群:从事电磁兼容性研究、6G通信技术研发以及对神经网络优化感兴趣的科研人员和工程师。 使用场景及目标:①研究6G通信中高频段电磁暴露对人体的影响;②开发更高效的电磁暴露评估工具;③优化神经网络架构以提高模型训练效率和预测精度。 其他说明:论文不仅提出了理论框架,还提供了完整的代码实现,方便读者复现实验结果。此外,论文还讨论了未来的研究方向,包括扩展到更高频段(如300GHz)的数据处理、引入强化学习优化超参数、以及实现多物理场耦合的智能电磁暴露评估系统。建议读者在实际应用中根据具体需求调整模型架构和参数,并结合真实数据进行验证。
内容概要:本文是北京金融科技产业联盟发布的《基于数据空间的金融数据可信流通研究报告》,探讨了金融数据可信流通的现状、挑战和发展前景。文章首先介绍了金融数据在数字化转型中的重要性及其面临的隐私保护和安全挑战。接着,文章详细阐述了数据空间的概念及其发展历程,尤其是可信数据空间(TDM)在我国的发展情况。文中还深入分析了金融数据可信流通的典型应用场景、关键技术和方案架构,如数据访问控制、数据使用控制、智能合约、数据脱敏等。最后,文章展示了多个典型场景应用案例,如中信银行总分行数据流通管控、工银金租数据流通、银联安全生物特征支付等,并总结了当前可信数据空间建设中存在的法规、技术、标准和商业模式挑战,提出了相应的政策建议。 适用人群:金融行业从业者、数据安全管理人员、政策制定者、科技研发人员等。 使用场景及目标:①理解金融数据可信流通的重要性和挑战;②学习可信数据空间的关键技术和应用场景;③探索金融数据可信流通的具体实践案例;④了解当前可信数据空间建设的瓶颈和未来发展方向。 其他说明:本文不仅提供了详尽的技术和应用分析,还提出了具体的政策建议,有助于推动金融数据可信流通的健康发展。阅读本文可以帮助读者深入了解金融数据安全保护和高效利用的最佳实践,为相关政策和技术的发展提供参考。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值