机器人走迷宫(dfs)
2024-09-06 18:38:34
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1590
#include <stdio.h>
#include <string.h>
int n,m,s_x,s_y,e_x,e_y;
char map[][]; int Deal(char c)
{
if(c=='R'&&map[s_x][s_y+]!='#')
{
s_y++;
if (s_x==e_x&&s_y==e_y)
return ;
}
else if(c=='L'&&map[s_x][s_y-]!='#')
{
s_y--;
if (s_x==e_x&&s_y==e_y)
return ;
}
else if(c=='U'&&map[s_x-][s_y]!='#')
{
s_x--;
if (s_x==e_x&&s_y==e_y)
return ;
}
else if(c=='D'&&map[s_x+][s_y]!='#')
{
s_x++;
if (s_x==e_x&&s_y==e_y)
return ;
}
return ;
}
int main()
{
char str[],s[][];
scanf("%d %d",&n,&m);
memset(map,'#',sizeof(s));//初始化全为墙
for (int i = ; i < n; i ++)
{
scanf("%s",s[i]);
for (int j = ; j < m; j ++)
{ if (s[i][j]=='S')
{
s_x = i+;
s_y = j+;
}
if (s[i][j]=='T')
{
e_x = i+;
e_y = j+;
}
map[i+][j+] = s[i][j];//给图像周围增加一堵墙,防止出界 }
} int ans = ,k;
scanf("%d",&k);
scanf("%s",str);
for (int i = ; i < k; i ++)
{
ans = Deal(str[i]);
if (ans)
break;
}
if (ans)
puts("Yes");
else
puts("No");
return ;
}
最新文章
- [LeetCode] Integer Break 整数拆分
- yum使用点滴
- java异常
- linux crontab定时任务调用CI框架PHP代码
- sudo add-apt-repository no found解决方法
- LLBL Gen Template Studio 2.x
- Liferay 6.2 改造系列之二十三:修改Liferay原始主题中";技术支持:Liferay";字样
- oracle组查询
- Blog Explanation
- MTK平台缩写
- 计数排序之python 实现源码
- 【Android Developers Training】 13. 支持不同平台版本
- vue2.0引入腾讯地图
- 给出打印结果-setTimeout
- 求字符串空格、数字、字母个数--JAVA基础
- Linux下进程通信之管道
- 在Linux中复制文件夹下的全部文件到另外文件夹
- FILE SIGNATURES TABLE
- struts2框架之类型转换(参考第二天学习笔记)
- Druid监控页面配置与使用
热门文章
- HDU_1698_Just a Hook_线段树区间更新
- Style在Android中的继承关系
- Java多线程学习笔记(三)——Future和FutureTask
- Vue中this.$router.push参数获取(通过路由传参)【路由跳转的方法】
- Django - orm字段类型介绍
- Spring Web MVC常用配置汇总
- 第六节:pandas函数应用
- (41)Spring Boot 使用Java代码创建Bean并注册到Spring中【从零开始学Spring Boot】
- angular的又一本好书
- iOS的四种传值方式