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

一文搞懂数据标注 数据标注即通过分类、画框、标注、注释等,对图片、语音、文本等数据进行处理,标记对象的特征,以作为机器学习基础素材的过程。简言之,就是需要给数据做好标注,这样机器就能知道学习哪些内容。 阅读详情

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

奇偶剪枝:

	temp=t-abs(x-a)-abs(y-b)-step;
	if(temp<0||temp&1)
		return ;

题意描述:s能否在t秒的时候恰好到达d如果能输出yes否则输出no。
这个是AC的代码

#include<stdio.h>
#include<string.h>
#include<math.h>
 
int book[10][10];
char e[10][10];
int a,b,n,m,t,flag;

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

void dfs(int x,int y,int step)
{
	int tx,ty,k,temp;
	if(x==a&&y==b&&step==t)
	{
		flag=1;
		return ;
	}	
	
	temp=t-abs(x-a)-abs(y-b)-step;
	if(temp<0||temp&1)
		return ;
	for(k=0;k<4;k++)
	{
		tx=next[k][0]+x;
		ty=next[k][1]+y;
		
		if(tx<1||ty<1||tx>n||ty>m)
			continue;
			
		if(book[tx][ty]==0&&e[tx][ty]!='X')
		{
			book[tx][ty]=1;
			dfs(tx,ty,step+1);
			if(flag==1)
				return ;
			book[tx][ty]=0;
		}
	}
}

int main(void)
{
	int i,j,x,y,count;
	while(scanf("%d%d%d",&n,&m,&t)!=EOF)
	{
		count=0;flag=0;
		if(m==0&&n==0&&t==0)
			break;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=m;j++)
			{
				scanf(" %c",&e[i][j]);
				if(e[i][j]=='S')
				{
					x=i;
					y=j;
				}
				if(e[i][j]=='D')
				{
					a=i;b=j;
				}
				if(e[i][j]=='X')
					count++;
				book[i][j]=0;
			}
		}
		if(m*n-count<=t)//这一步操作贼有用。
		{
			printf("NO\n");
			continue;
		}
		book[x][y]=1;
		dfs(x,y,0);
		if(flag==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

这个代码只有交G++才能AC,交C和C++都是TLE,有哪位大佬能指点一下这是为啥吗?

#include<stdio.h>
#include<string.h>
#include<math.h>


char e[10][10];
int book[10][10],n,m,t,flag=0;
int a,b;

void dfs(int x,int y,int step)
{
	int k;
	int next[4][2]={1,0, -1,0, 0,1, 0,-1};
	if(step>t-abs(a-x)-abs(b-y))
		return ;
	if(x==a&&y==b)
	{
		if(step==t)
			flag=1;	
		return ;
	}
	if(t==step&&(x!=a||y!=b))
		return ;
	int tx,ty;
	for(k=0;k<4;k++)
	{
		tx=x+next[k][0];
		ty=y+next[k][1];
		
		if(tx<1||ty<1||tx>n||ty>m)
			continue;
		if(book[tx][ty]==0&&e[tx][ty]!='X')
		{
			book[tx][ty]=1;
			dfs(tx,ty,step+1);
			if(flag==1)
				return ;
			book[tx][ty]=0;
		}
	}
}

int main(void)
{
	int x,y;
	while(~scanf("%d%d%d",&n,&m,&t))
	{
		if(m==0&&n==0&&t==0)
			break;
		flag=0;
		memset(book,0,sizeof(book));
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
			{
				scanf(" %c",&e[i][j]);
				if(e[i][j]=='S')
				{
					x=i;
					y=j;
				}
				if(e[i][j]=='D')
				{
					a=i;b=j;
				}
			}
		book[x][y]=1;
		dfs(x,y,0);
		if(flag==0)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
 } 


超临界二氧化碳发电技术深度解析 超临界二氧化碳发电技术正在突破传统热电转换的物理边界。作为新一代发 阅读详情

相关推荐

嵌入式存储进阶:除了KV存储,EasyFlash的IAP和LOG功能怎么玩?

本文深入探讨了嵌入式存储方案EasyFlash的高级功能,包括在线固件升级(IAP)和闪存日志存储(LOG)。通过详细解析IAP的双区备份设计和LOG的环形缓冲区架构,提供硬件适配、安全升级流程和日志管理技巧等实战指南,帮助开发者在物联网设备中实现可靠的数据存储和固件更新。

weixin_29280219的博客 419

HDU-1010Tempter 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): 157407 Accepted Submission(s): 41882 Problem Description The doggie...

孤风的博客 587

从S参数到SPICE模型:Cadence Sigrity Boardband SPICE完整使用指南

本文详细介绍了Cadence Sigrity Boardband SPICE工具的核心价值与完整使用流程。该工具通过矢量拟合算法,将复杂的多端口S参数文件转化为无源、紧凑且高精度的SPICE等效电路模型,从而极大提升时域仿真效率。指南涵盖了从数据导入、关键参数配置、模型精度验证到集成应用于PowerSI等系统级仿真的全步骤,是信号与电源完整性分析的必备利器。

defi6farmer的博客 449

hdu 1010 Tempter of the Bone(dfs+剪枝)

题目链接:hdu 1010 Tempter of the Bone(dfs+剪枝) 题意:狗狗从S出发,要在正好t秒的时候到达D,每一块地只能走一次,X代表墙不能走,问能否到达 思路:深搜,但是需要剪枝,每走一步,判断能否在剩下的时间中不考虑墙通过最短的路到达出口,若不能直接返回。 #include&lt;cstdio&gt; #include&lt;cstring&gt; #incl...

yz467796454的博客 296

国产Hygon处理器MCA架构总结

Hygon处理器MCA架构总结

weixin_48576628的博客 4625

MATLAB实战:手把手教你实现Gardner环路位同步(附完整代码)

本文通过MATLAB实战,详细讲解了Gardner环路位同步算法的原理与实现。内容涵盖插值滤波器、定时误差检测、环路滤波器与数控振荡器等核心模块,并提供完整代码和调试技巧,帮助读者掌握数字通信中关键的符号定时同步技术。

weixin_29048775的博客 180

HDU1010 Tempter of the Bone(DFS+奇偶剪枝)

题目:HDU1010 Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 161732Accepted Submission(s): 42908 Problem Descriptio...

CarreLiu 225

AFSim2.9.0学习笔记 —— 2、AFSim的Wizard软件概述(ArkSIM集成开发环境 (IDE))

AFSim2.9.0学习笔记 —— 2、AFSim的Wizard软件详述(ArkSIM集成开发环境 (IDE))

938

HDU1010 Tempter of the Bone(深度优先搜索DFS+奇偶性剪枝)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:       给定一个迷宫图,问T步能否找到门。 分析:       这是个DFS的奇偶剪枝问题,先附张图。  对于代码中的解释 其中t-w为剩余的步数或者说时间, s1+s2为剩余步数, 如果走偶数步要求的时间是奇数,或者走奇数步要求的时间是偶数,都明显不可行 而轻...

Sean 298

AI自瞄原理剖析(四)从Yolo推理坐标到屏幕坐标:基于FOV视角与焦距的坐标变换与精准瞄准

从Yolo推理框架得到的坐标到屏幕坐标的转换是一个涉及到FOV视角、焦距以及分辨率的复杂过程。通过数学公式,我们可以将推理框坐标反推为游戏内的实际坐标,并最终映射到屏幕坐标系中。利用这些信息,AI自瞄系统能够精确计算出准星从当前位置移动到敌人位置的距离,实现精准的自动瞄准。通过这种方法,AI自瞄系统能够在不同的游戏环境下灵活应对,提供高度精确的操作体验。在AI自瞄系统中,目标检测仅仅是第一步,获取到预测框的坐标后,我们还需要将这些坐标转换为实际屏幕上的精确位置。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1352

Python编程基础05:运算符与表达式

文章目录一、算术运算符1、分类说明表2、注意事项3、案例演示任务1、计算成绩差与平均成绩课堂练习:编程处理带余除法。任务2、打印购物小票 运算符就是专门用于告诉程序执行特定运算或逻辑操作的符号。表达式是指由常量、变量和运算符组成的一个算式。编写程序对数据进行处理,其实处理就是对数据实施各种各样的运算,搞懂运算符与表达式是我们编写程序的基础性工作,本次讲课笔记通过案例讲解各种运算符的用法以及正确书写Python表达式的注意事项。 一、算术运算符 Python中的算术运算符就是用来处理四则运算的符号,也是

howard2005的专栏 3131

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

奇偶剪枝得到新技能

n-1 744

30天入门 SAP BTP 开发系列之七:动手在 SAP BTP 上开发第一个 ABAP 程序

本教程从理论转向实践,指导如何在SAP BTP上创建首个ABAP程序。首先通过Booster向导在Trial账号中配置ABAP环境,需确保已启用Cloud Foundry并创建Space。成功创建ABAP实例后,使用ABAP Development Tool连接环境:下载服务密钥文件,导入工具获取连接URL,即可建立项目开始编码。教程提供了从环境搭建到开发工具配置的完整流程,帮助ABAP开发者快速上手BTP云开发。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1710

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 5433

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

【HDU】1010Tempter of the Bone【dfs+剪枝】

单纯用dfs会超时 要用剪枝优化 提供一组变态数据 6 6 37 S..... ...... ...... ...... ...... D..... NO #include&lt;bits/stdc++.h&gt; #include&lt;cstring&gt; using namespace std; struct node{ int x,y; }; int N,M,T; c...

以梦为马,诗酒趁年华的博客 140

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

题意 狗狗要在特定时刻逃出N*M迷宫,迷宫已输入,‘.’表示可以走的路,’#’表示不能走的墙,’S’表示开始位置,‘D’表示结束位置。不能走回头路。 思路以及细节点 输入时将起点、终点位置记录,并将墙的vis置为true(不能 再 走了) DFS,先贴代码

Chen_yuazzy的博客 1765

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

hdu-1010 Tempter of the Bone(DFS+奇偶剪枝)

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): 109915 Accepted Subm

oYinGui1 865

dfs与奇偶剪枝 Tempter of the bone——hdu1010

dfs与奇偶剪枝 Tempter of the bone——hdu1010

2301_80093604的博客 1081

HDU1010Tempter 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): 166686 Accepted Submission(s): 44241 Problem Description The doggie foun...

DouglasConnor的博客 256

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): 133736    Accepted Submission(s): 35982 Problem Description The dog

Head_Hard的博客 269

Tempter of the Bone HDU - 1010 DFS剪枝

Tempter of the Bone HDU - 1010 小狗在一个古老的迷宫里发现了一块骨头,这让它很着迷。然而,当它捡起这块骨头时,迷宫开始摇晃,小狗可以感觉到地面在下沉。他意识到那块骨头是个陷阱,于是拼命地想走出迷宫。 迷宫是一个长方形的,大小为N×m。迷宫里有一扇门。在开始的时候,门是关闭的,它会在第t秒打开一小段时间(不到1秒)。因此,小狗必须在第t秒准时到达门口。在每一秒钟,他可以...

qq_41852483的博客 237

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): 54622 Accepted Submission(s): 14723 Problem Description The doggie f

公众号:ByteCode 1291

HDU 1010 Tempter of the Bone 奇偶剪枝 DFS

题目 题意 根据地图,'S'为开始位置,'D'为门的位置,' . '为空地,'X'为墙,不能经过, 问:在指定的时间,是否能到达'门'的位置. 注意:路不可以重复经过,时间也要刚好是 t ,不能少. 分析 之前用了BFS,是不对的。 因为使用BFS的话,求得的是最短路径(T时间到终点,且是最短路径)。然而,这一题的路径不一定是最短的。 参考博客 代...

117瓶果粒橙 176

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

http://acm.hdu.edu.cn/showproblem.php?pid=1010 大神题解报告http://acm.hdu.edu.cn/forum/read.php?tid=6158 关于剪枝,没有剪枝的搜索不太可能,这题老刘上课的时候讲过两个剪枝,一个是奇偶剪枝,一个是路径剪枝 奇偶剪枝: 把矩阵标记成如下形式: 0,1,0,1,0 1,0,1...

aocang4831的博客 131

HDU 1010 —— Tempter of the Bone DFS+剪枝

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:从S走到D,其中X是墙,不能走;给定时间 t ,问能否从S到D正好花费 t 时间(一步即为一秒); 思路:用DFS+剪枝; 此处有两种剪枝: 1、从S到D的最短时间是 tmp = abs(sx-dx)+abs(sy-dy),如果 tmp > t,显然是“NO”; 2、如果 t

0x3f3f3f3f 465

Tempter of the Bone HDU - 1010 DFS+剪枝

求迷宫中是否有路径长为t的起点到终点的路径。 一开始没有看清题意,以为是否有t长度内的路径,直接想到最短路径BFS。 BFS适合解决的问题类型 结点A出发到结点B是否有解? 结点A出发到结点B的路径哪条最短?(最短路) 然而很快WA了。此题不能使用BFS,因为是求是否有路径长为t的解。用BFS无法深入每一条路径。接着,我想想到BFS,深搜每一条路径,并记录路径长度再与t进行比较。没有剪枝的暴力...

Stay Hungry, Stay Foolish. 328
上一篇: HDU 2594 Simpsons’ Hidden Talents(kmp)
下一篇: POJ 4227 反正切函数的应用
鳳九~
博客等级 码龄8年 1384粉丝 215原创
评论 10
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值