杭电1010-Tempter of the Bone(BFS)

极智AI | 详解 ViT 算法实现 大家好,我是极智视界,本文详细介绍一下 ViT 算法的设计与实现,包括代码。 阅读详情

Tempter of the Bone

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


Problem Description
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<cstdio>
#include<cmath>
#include<cstring>
char cmap[10][10];
int m,n,s,mov[4][2]={1,0,-1,0,0,1,0,-1};
int vis[10][10],flag,sx,sy,ex,ey;
bool can(int x,int y)//判断当前点能不能走
{
	if(x<0||x>m-1||y<0||y>n-1||cmap[x][y]=='X'||vis[x][y])
	return false ;
	return true ;
}
void dfs(int x,int y,int step)
{
	if(cmap[x][y]=='D')
	{
		if(step==s)
		{
			flag=1;
			return ;
		}
		return ;
	}
	int xx,yy,i;
	
	int as=abs(x-ex)+abs(y-ey);
	if((s-as-step)%2||as+step>s)//奇偶剪枝
	return ;
	
	if(flag)//记得加上这一句优化
	return ;
	
	for(i=0;i<4;i++)
	{
		xx=x+mov[i][0];
		yy=y+mov[i][1];
		if(can(xx,yy))
		{
			vis[xx][yy]=1;
			dfs(xx,yy,++step);
			vis[xx][yy]=0;
			step--;
		}
	}
}
int main()
{
	int i,j;
	while(scanf("%d%d%d",&m,&n,&s),m||n||s)
	{
		memset(vis,0,sizeof(vis));
		for(i=0;i<m;i++)
		{
			scanf("%s",cmap[i]);
			for(j=0;j<n;j++)
			{
				if(cmap[i][j]=='S')
				{
					sx=i;
					sy=j;
				}
				if(cmap[i][j]=='D')
				{
					ex=i;
					ey=j;
				}
			}
		}
		flag=0;
		vis[sx][sy]=1;
		int best=abs(ex-sx)+abs(ey-sy);
		if((best+s)&1)//判断开始能否到达,如果不能就continue!
		{
			 printf("NO\n");
			 continue;
		}
		dfs(sx,sy,0);
		if(flag)
		printf("YES\n");
		else
		printf("NO\n");
	}
	return 0;
}






AI上推荐 之 NeuralCF与PNN模型(改变特征交叉方式) 1. 前言 随着信息技术和互联网的发展, 我们已经步入了一个信息过载的时代,这个时代,无论是信息消费者还是信息生产者都遇到了很大的挑战: 信息消费者:如何从大量的信息中找到自己感兴趣的信息? 信息生产者:如何让自己生产的信息脱颖而出, 受到广大用户的关注? 为了解决这个矛盾, 推荐系统应时而生, 并飞速前进,在用户和信息之间架起了一道桥梁,一方面帮助用户发现对自己有价值的信息, 一方面让信息能够展现在对它感兴趣的用户前面。 推荐系统近几年有了深度学习的助推发展之势迅猛, 从前深度学习的传统推荐模型(协 阅读详情

相关推荐

Streamlit(九) widgets-input

st.text_input / st.number_input / st.date_input / st.time_input 源码路径:${python}\Lib\site-packages\streamlit\elements\text_widgets.py(number_input.py, time_widgets.py) st.text_input st.text_input(label, value="", max_chars=None, key=None,\

heianduck的博客 3354

Tempter of the Bone

暑假的时候,小明和朋友去迷宫中寻宝。然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱!他们想尽一切办法逃出去。 迷宫是一个大小为 N*M 的长方形,迷宫中有一扇门。一开始,门是关着的,他会在第 t 秒的时间打开。因为,小明和朋友必须在第 t 秒到大门口。每一秒,他都可以向上下左右四个方向移动一个点。一旦他移动了,他刚才所在的点就消失,(这意味着他不能回到他已经走过...

qq_43301061的博客 313

图像去雨:超详细手把手写 pytorch 实现代码(带注释)

占个坑,过几天来写

书山有路,学海无涯! 1万+

Tempter of the Bone II(BFS)

炸弹问题,题中加了一个小人拿到i个炸弹后去炸墙,一个炸弹能炸一面墙 一步所需时间为1秒,安炸弹到爆炸所需要一秒,也就是说从走到那面墙开始算起到通过那面墙所需要的时间为2秒 问多少秒后可以到达出口 如果出不去就输出-1 记录S点的坐标后开始BFS 由于有炸错墙的可能性,所以炸了墙之后不能在原图map中修改,需要有一个记录状态的数组 这里叫做state 在结构体里 state[i]

DIOML的博客 551

【QT开发教程】QMatrix4x4类详解及实战应用:Qt中的4x4矩阵变换

在计算机图形学和三维图形应用中,矩阵变换是一个核心概念。Qt框架提供了QMatrix4x4类,用于处理4x4矩阵变换,帮助开发者在三维空间中进行复杂的几何计算。本文将深入探讨QMatrix4x4的功能及其在Qt应用中的实际应用。

科技改变人类,技术成就未来 717

芒果YOLOv5改进107:ARConv自适应旋转卷积,全网首发 | 即插即用:以增强其表征能力,从而准确检测方向物体,ICCV顶会论文idea

ARConv自适应旋转卷积,全网首发 | 即插即用:以增强其表征能力,从而准确检测方向物体,ICCV顶会论文idea

包括YOLOv5、YOLOv7、YOLOv8等模型改进 956

dfs/bfs--Tempter of the Bone

Tempter of the Bone 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 re...

duganlx的博客 415

基于 Mask R-CNN 的实例分割:从零开始构建一个强大的分割模型

在本文中,我们将介绍如何使用 Mask R-CNN(Region-based Convolutional Networks with Masks)实现实例分割。实例分割是计算机视觉中的一种任务,旨在识别并分割图像中的各个对象。我们将讨论如何准备数据集、配置 Mask R-CNN 模型并在自定义数据集上进行训练。

斌擎科技 1243

C - Tempter of the Bone 杭电1010

Description 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 re

lalalademaxi的博客 288

46、聚类算法在智能交通数据分析中的应用

本文探讨了聚类算法在智能交通数据分析中的应用,介绍了K-均值算法、K-中心点算法和基于模型的聚类算法的基本原理及特点,并结合实际交通数据讨论了其应用场景与挑战。通过聚类分析,能够从海量交通数据中发现隐藏模式,为交通管理和规划提供科学依据。文章还展示了具体的案例分析和实现流程,为未来智能交通系统的发展提供了参考。

zz67890的博客 133

AES-128-CMAC:背景、汽车应用、CAPL 实现与开源工具验证

本文详解车载诊断中AES-128-CMAC算法的原理与应用,涵盖其在UDS安全访问、刷写鉴权、SecOC认证及密钥派生中的核心作用。结合真实汽车电子场景,提供纯CAPL实现代码与测试脚本,并通过pycryptodome进行逐字节验证,确保算法正确性。全程基于CANoe实测数据,可直接用于HIL环境复现,助力开发者高效落地汽车网络安全方案。

蚂蚁小兵 113

HDU 2128Tempter of the Bone II

Tempter of the Bone II Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 98304/32768K (Java/Other) Total Submission(s) : 3   Accepted Submission(s) : 1 Problem Description The doggie

Dream_M 1402

基于Simulink的发动机管理系统中的自适应增压控制系统设计

通过上述详细设计步骤,我们成功开发了一个基于Simulink的自适应增压控制系统。该系统不仅能够实时监测和预测发动机的运行状态,动态调整增压压力目标值,还具备实时监控、故障诊断和保护功能,确保系统的安全性和可靠性。此外,通过仿真实验和硬件在环测试,我们验证了系统的性能,并对其进行了优化,使其能够更好地满足实际应用需求。这个项目展示了如何利用MATLAB/Simulink的强大功能,结合控制理论和工程实践,开发出高效、可靠的自适应增压控制系统。

MHD0815的博客 220

hdu_1010 Tempter of the Bone

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 分析:题意即为再规定的时间内从开始点走在结束点。

徵羽調_xiao賤的专栏 882

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

HDU 1010 Tempter of the Bone(DFS,奇偶剪枝)

Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 101688    Accepted Submission(s): 27539 Problem Description The

AC_Dreameng 5432

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

杭电acm1010 Tempter of the Bone

Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 133177    Accepted Submission(s): 35811 Problem Description The

cwhong_723的博客 273

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

杭电1010 Tempter of the Bone (DFS+奇偶剪枝)

Problem Description 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

少年白马 240

杭电1010Tempter of the Bone(dfs)

Problem Description 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

qq_52699147的博客 241

HDU 题目1010 Tempter of the Bone

Tempter of the BoneTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 125699 Accepted Submission(s): 33910Problem Description The doggie found

南风古 291

【杭电oj】1010 - Tempter of the Bone(dfs,奇偶剪枝,好题)

Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 97047    Accepted Submission(s): 26333 Problem Description The

wyg1997 847

HDU1010(Tempter of the Bone)深搜

HDU1010 Tempter of the Bone 广搜每走 思路:简单的深搜,如果map[nextx][nexty]!='X',则以该最后点为当前节点继续搜,若继续搜没有路可走,则释放当前节点(即原来标记过,恢复为未标记,以便再以其他节点搜索时经过该点),回到上一节点,return.由于step是局部变量,其生命周期随着当前层的DFS()函数结束而结束,所以返回上一层时,step的值就是

colorsunlight的专栏 1282

杭电1010---Tempter of the Bone

Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 83349    Accepted Submission(s): 22707  Problem Description The doggie

在未来等你的专栏 545

1010 Tempter of the Bone (杭电) (图Graph)

Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 51809Accepted Submission(s): 13939 Problem Description The doggie fou...

weixin_30918633的博客 85

HDU -2128 Tempter of the Bone II(BFS)

Tempter of the Bone II Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 98304/32768 K (Java/Others) Problem Description The doggie found a bone in an ancient maze, which fascinated him a l...

名字太长容易被发现并打死 503

Tempter of the Bone (深搜+剪枝)

第一次遇到剪枝这一概念,主要是用来减少步骤的吧,WA了十四次  尴尬 H - Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description The doggie fo

yinghui_yht的博客 4916

HDU(1010)bfs+剪枝 Tempter of the Bone

New~ 欢迎参加2016多校联合训练的同学们~                                         Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submis

昨日明眸 1492
上一篇: 奇偶剪枝
下一篇: 杭电1004-Let the Balloon Rise
Eric_keke
博客等级 码龄12年 37粉丝 221原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值