Tempter of the Bone

本文介绍了一个迷宫逃脱问题,玩家需要帮助一只小狗在一个N*M的矩形迷宫中找到出口。迷宫中包含墙壁、起点、终点及空地,小狗必须在限定时间内到达出口才能成功逃脱。

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

主要方法:主要是深搜,减枝(可以用到奇偶减枝法)
题目描述:'S'表示起点,'D'表示终点,'X'表示墙不能走,'.'表示是空的可以走,’T‘表示在T秒到达
                     如果可以在T秒内到达,则输出'YES',否则就输出’NO'。
 解题思路:先用递归到要走的终点,如果中途不通则回溯(这里要用到奇偶减枝,否则会超时),然后计算出总共的时间,如果时间在T秒内则说明可以,否则不行。

代码
#include<stdio.h>

char a[100][100];
int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}};
int n, m, t, sx, sy, ex, ey;
int i, j, num, key;


void dfs(int nx,int ny,int sum)
{
    int k, nextx, nexty, u, v;
    if(nx==ex &&ny==ey && sum==t)
        key=1;
    if(key)
        return;
        u=ex-nx;
        v=ey-ny;
        if(u<0)
            u=-u;
        if(v<0)
            v=-v;
    if((u+v)%2!=(t-sum)%2)    //奇偶减枝
        return;
    for(k=0; k<4; k++)
    {
        nextx=nx+dir[k][0];
        nexty=ny+dir[k][1];
        if(nextx>=0 && nextx<n && nexty>=0 && nexty<m && a[nextx][nexty]!='X')
        {
            a[nextx][nexty]='X';
            dfs(nextx,nexty,sum+1);
            a[nextx][nexty]='.';   //如果此路不通则回溯到上一层
        }
    }
}
int main()
{
    while(scanf("%d%d%d", &n, &m, &t)!=EOF)
    {
        getchar();
        if(n==0&&m==0&&t==0)
            break;
        key=0;
        num=0;
        for(i=0; i<n; i++)
        {
            for(j=0; j<m; j++)
            {
                scanf("%c", &a[i][j]);
                if(a[i][j]=='S')
                {
                    sx=i; sy=j;
                }
                else if(a[i][j]=='D')
                {
                    ex=i; ey=j; num++;
                }
                else if(a[i][j]=='.')
                {
                    num++;
                }
            }
            getchar();
        }
        a[sx][sy]='X';
        if(num>=t)
            dfs(sx, sy, 0);
        if(key)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


基于径向基函数神经网络RBFNN的自适应滑模控制学习(Matlab代码实现)内容概要:本文介绍了基于径向基函数神经网络(RBFNN)的自适应滑模控制方法,并提供了相应的Matlab代码实现。该方法结合了RBF神经网络的非线性逼近能力和滑模控制的强鲁棒性,用于解决复杂系统的控制问题,尤其适用于存在不确定性和外部干扰的动态系统。文中详细阐述了控制算法的设计思路、RBFNN的结构与权重更新机制、滑模面的构建以及自适应律的推导过程,并通过Matlab仿真验证了所提方法的有效性和稳定性。此外,文档还列举了大量相关的科研方向和技术应用,涵盖智能优化算法、机器学习、电力系统、路径规划等多个领域,展示了该技术的广泛应用前景。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的研究生、科研人员及工程技术人员,特别是从事智能控制、非线性系统控制及相关领域的研究人员; 使用场景及目标:①学习和掌握RBF神经网络与滑模控制相结合的自适应控制策略设计方法;②应用于电机控制、机器人轨迹跟踪、电力电子系统等存在模型不确定性或外界扰动的实际控制系统中,提升控制精度与鲁棒性; 阅读建议:建议读者结合提供的Matlab代码进行仿真实践,深入理解算法实现细节,同时可参考文中提及的相关技术方向拓展研究思路,注重理论分析与仿真验证相结合。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值