HDU-1010-Tempter of the Bone

本文介绍了一种迷宫逃脱算法,通过奇偶剪枝优化搜索过程。算法要求角色在限定时间内找到出口,同时避免重复路径。文章详细解释了算法原理,并提供了一个具体的实现案例。

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

点击打开链接


Tempter of the Bone

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


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<stdio.h>  
#include<string.h>  
#include<math.h>  
using namespace std;  
int n,m,t,ex,ey,sx,sy;  
int flag,wall,res,rx,ry;  
int step;  
char a[80][80];  
int fx[]={1,-1,0,0},fy[]={0,0,1,-1};  
void dfs(int x,int y,int step)  
{  
    if(flag)  
    return ;  
    if(x==ex&&y==ey&&step==t)   //条件刚好,到终点时间刚好用完   
    {  
        flag=1;  
        return ;  
    }  
    rx=abs(x-ex);       //从当前位置到终点需要横向一定的步数  
    ry=abs(y-ey);	//从当前位置到终点需要纵向移动的步数  
    res=t-step-rx-ry;	//剩余时间==总时间-用去的时间-剩余步数  
    if(res<0||res%2!=0)  //看剩下的时间能能否到达终点,tem&1则是判断其是否偶数,根据LCY的奇  
    return ;            //偶性剪枝可得tem必须是偶数,是奇数则不行  
      
      
  
    for(int i=0;i<4;i++)  
    {  
        int xx=x+fx[i],yy=y+fy[i];  
        if(xx>=0&&xx<m&&yy>=0&&yy<n&&a[xx][yy]!='X')  
        {  
            a[xx][yy]='X';      //走过的地方变为墙   
            dfs(xx,yy,step+1);  
            a[xx][yy]='.';      //迷宫还原,以便下次广搜  
        }  
    }  
 }   
int main()  
{  
    while(~scanf("%d%d%d",&m,&n,&t))  
    {  
        int i,j;  
        wall=0;  
        flag=0;  
        step=0;  
        if(m==0&&n==0&&t==0)  
        break;  
        for(i=0;i<m;i++)  
            scanf("%s",a[i]);  
        for(i=0;i<m;i++)  
            for(j=0;j<n;j++)  
            {  
                if(a[i][j]=='S')    //找到起点   
                sx=i,sy=j;  
                if(a[i][j]=='D')    //找到终点   
                ex=i,ey=j;  
                if(a[i][j]=='X')    //记录墙的总数   
                wall++;   
            }  
        if(m*n-wall<=t)  //临街wall+t+1==m*n,所以正常情况下m*n-wall应该>t   
        {  
            printf("NO\n");  
            continue;  
        }  
        a[sx][sy]='X';  //出发点是不可能再走的了,变为墙    
        dfs(sx,sy,step);      
        if(flag)  
        printf("YES\n");  
        else printf("NO\n");  
    }  
}  



内容概要:本文介绍了奕斯伟科技集团基于RISC-V架构开发的EAM2011芯片及其应用研究。EAM2011是一款高性能实时控制芯片,支持160MHz主频和AI算法,符合汽车电子AEC-Q100 Grade 2和ASIL-B安全标准。文章详细描述了芯片的关键特性、配套软件开发套件(SDK)和集成开发环境(IDE),以及基于该芯片的ESWINEBP3901开发板的硬件资源和接口配置。文中提供了详细的代码示例,涵盖时钟配置、GPIO控制、ADC采样、CAN通信、PWM输出及RTOS任务创建等功能实现。此外,还介绍了硬件申领流程、技术资料获取渠道及开发建议,帮助开发者高效启动基于EAM2011芯片的开发工作。 适合人群:具备嵌入式系统开发经验的研发人员,特别是对RISC-V架构感兴趣的工程师和技术爱好者。 使用场景及目标:①了解EAM2011芯片的特性和应用场景,如智能汽车、智能家居和工业控制;②掌握基于EAM2011芯片的开发板和芯片的硬件资源和接口配置;③学习如何实现基本的外设驱动,如GPIO、ADC、CAN、PWM等;④通过RTOS任务创建示例,理解多任务处理和实时系统的实现。 其他说明:开发者可以根据实际需求扩展这些基础功能。建议优先掌握《EAM2011参考手册》中的关键外设寄存器配置方法,这对底层驱动开发至关重要。同时,注意硬件申领的时效性和替代方案,确保开发工作的顺利进行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值