HDU-1035 Robot Motion 模拟问题(水题)
题目链接:https://cn.vjudge.net/problem/HDU-1035
水题
代码
#include <cstdio>
#include <map>
int height, width, sp, dir[4][2]={1, 0, 0, -1, -1, 0, 0, 1};
std::map<char, int> todir;
char map[15][15];
int solve(int x, int y, int step, int vis[][15], int &loop){
if (x<0 || y<0 || x>=width || y>=height) {loop=0; return step;}
if (vis[y][x]) {loop=step-vis[y][x]; return step-loop;}
vis[y][x]=step;
return solve(x+dir[todir[map[y][x]]][0], y+dir[todir[map[y][x]]][1], step+1, vis, loop);
}
int main(void){
todir['E']=0; todir['N']=1;
todir['W']=2; todir['S']=3;
while (scanf("%d%d", &height, &width)==2 && height){
scanf("%d", &sp);
for (int y=0; y<height; y++) scanf("%s", map[y]);
int vis[15][15]={0}, loop, cnt=solve(sp-1, 0, 1, vis, loop);
if (!loop) printf("%d step(s) to exit\n", cnt-1);
else printf("%d step(s) before a loop of %d step(s)\n", cnt-1, loop);
}
return 0;
}
HDU-1035 Robot Motion 模拟问题(水题)的更多相关文章
- [ACM] hdu 1035 Robot Motion (模拟或DFS)
Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. ...
- HDOJ(HDU).1035 Robot Motion (DFS)
HDOJ(HDU).1035 Robot Motion [从零开始DFS(4)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DF ...
- hdu 1035 Robot Motion(模拟)
Problem Description A robot has been programmed to follow the instructions in its path. Instructions ...
- HDU 1035 Robot Motion(dfs + 模拟)
嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1035 这道题比较简单,但自己一直被卡,原因就是在读入mp这张字符图的时候用了scanf被卡. ...
- hdu 1035 Robot Motion(dfs)
虽然做出来了,还是很失望的!!! 加油!!!还是慢慢来吧!!! >>>>>>>>>>>>>>>>> ...
- 题解报告:hdu 1035 Robot Motion(简单搜索一遍)
Problem Description A robot has been programmed to follow the instructions in its path. Instructions ...
- (step 4.3.5)hdu 1035(Robot Motion——DFS)
题目大意:输入三个整数n,m,k,分别表示在接下来有一个n行m列的地图.一个机器人从第一行的第k列进入.问机器人经过多少步才能出来.如果出现了循环 则输出循环的步数 解题思路:DFS 代码如下(有详细 ...
- HDU 2096 小明A+B --- 水题
HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...
- hdu 2117:Just a Numble(水题,模拟除法运算)
Just a Numble Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- 接入gitment为hexo添加评论功能
title: 接入gitment为hexo添加评论功能 toc: false date: 2018-04-16 10:59:56 categories: methods tags: hexo gitm ...
- POJ 3188暴搜
题意: 思路: 裸的暴搜 --. 但是要注意如果你不用所有的按键就能输出最优解的话一定要把所有的字母都安排到一个位置-. 我的一群PE就是这么来的-- 为什么写的人这么少-- // by Sirius ...
- Android 数据存取
Android提供了Preference(配置),File(文件),SQLite数据和网络几种数据存取方式 SharedPreference提供了一种轻量级的数据存取方法,应用场合主要是比较少的配置信 ...
- springmvc整合mybatis实现商品列表查询
转载.https://blog.csdn.net/chizhuyuyu/article/details/82180404 https://www.jianshu.com/p/689bdd11bfcc. ...
- 2,HTTP请求应答返回码
200 OK 请求成功,一般用于Get和Post请求 300 多种选择.请求的资源可包括多个位置,响应的返回一个资源特征与地址的列表用于浏览器(client)选择 Multiple Choices 3 ...
- firewall 实现数据的端口转发
端口转发:firewall-cmd --add-port=80/tcp firewall-cmd --add-port=10050/tcp firewall-cmd --add-forward-por ...
- oc消息转发机制本质
第一级转发:主体不变,动态添加对应函数: 第二级转发:函数不变,切换接收主体: 第三极转发:函数签名不变,主体和函数都有可能变化: 1.使用函数的动态添加技术: 2.使用的类似is-a swzzing ...
- win10 无法访问XP 共享目录原因
win10 无法访问XP 共享目录原因 *现象: 在地址栏中输入\\192.168.100.5 (XP文件服务器),出现:.....找不到网络路径, 此连接尚未还原. ...
- 路飞学城Python-Day12
7月10日安排 完成所有函数作业和思维导图整理 [45.函数-生成器] 如果数据是有规律的,就可以先生成一个数据,等数据执行的时候再执行,也就是在真正调用数据之前,拿到数据的生成规律,而是拿到生 ...
- 解决vuex刷新页面数据丢失
1.前言 vue构建的项目中,vuex的状态存储是响应式的,当vue组件从store中读取状态的时候,若store中的状态发生变化,那么相应的组件也会得到高效刷新,问题来了,vuex存储的数据只是在页 ...