HDU 1035 Robot Motion(dfs + 模拟)
嗯...
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1035
这道题比较简单,但自己一直被卡,原因就是在读入mp这张字符图的时候用了scanf被卡...
注意初始化和dfs边界:如果超出图或者曾经被标记过则输出
AC代码:
#include<cstdio>
#include<cstring>
#include<iostream> using namespace std; char mp[][];
int k, a, b, c, flag[][]; inline void dfs(int x, int y){
if(x <= || y <= || x > a || y > b){
printf("%d step(s) to exit\n", k);
return;
}
if(flag[x][y] != ){
printf("%d step(s) before a loop of %d step(s)\n", flag[x][y] - , k - flag[x][y] + );//k - (flag[x][y] - 1)
return;
}
if(mp[x][y] == 'E'){
k++;
flag[x][y] = k;
dfs(x, y + );
}
else if(mp[x][y] == 'W'){
k++;
flag[x][y] = k;
dfs(x, y - );
}
else if(mp[x][y] == 'N'){
k++;
flag[x][y] = k;
dfs(x - , y);
}
else if(mp[x][y] == 'S'){
k++;
flag[x][y] = k;
dfs(x + , y);
}
} int main(){
while(scanf("%d%d%d", &a, &b, &c) != EOF && a + b){
memset(flag, , sizeof(flag));
for(int i = ; i <= a; i++)
for(int j = ; j <= b; j++)
cin >> mp[i][j];//scanf会被卡
k = ;
dfs(, c);
}
return ;
}
AC代码
HDU 1035 Robot Motion(dfs + 模拟)的更多相关文章
- 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(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 代码如下(有详细 ...
- [ACM] hdu 1035 Robot Motion (模拟或DFS)
Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. ...
- 题解报告:hdu 1035 Robot Motion(简单搜索一遍)
Problem Description A robot has been programmed to follow the instructions in its path. Instructions ...
- hdu1035 Robot Motion (DFS)
Robot Motion Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- hdoj 1035 Robot Motion
Robot Motion Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】
...
随机推荐
- 【转载】Java集合容器全面分析
转自:http://blog.csdn.net/garfielder007/article/details/52143803 简介: 集合类Collection不是Java的核心类,是Java的扩展类 ...
- python正则匹配次数,贪婪和非贪婪
贪婪模式 {m,n}表示匹配子串的次数>=m and <=n,再此分为内匹配次数尽可能的多 贪婪模式 {,n}表示 >=0 and <=n 贪婪模式 {m,} 表示> ...
- linux下实现keepalived+nginx高可用
1 nginx负载均衡高可用 1.1 什么是负载均衡高可用 nginx作为负载均衡器,所有请求都到了nginx,可见nginx处于非常重点的位置,如果nginx服务器宕机后端web服务将无法提供服务, ...
- Jmeter注册100个账户的三个方法
Jmeter注册账户比如注册成千上万个账户,如何快速实现呢? 三种方法分别举例注册5个账户 1)添加CSV data config_txt 2)添加CSV data config_csv 3)函数助手 ...
- 【 SSH 配置参考】
applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xm ...
- Boxes and Candies
问题 G: Boxes and Candies 时间限制: 1 Sec 内存限制: 128 MB[提交] [状态] 题目描述 There are N boxes arranged in a row. ...
- 压缩/批量压缩/合并js文件
写在前面 如果文件少的话,直接去网站转化一下就行. http://tool.oschina.net/jscompress?type=3 1.压缩单个js文件 cnpm install uglify-j ...
- 序列化--IOSerialize
序列化与反序列化 序列化:将对象转换为二进制 反序列化:将二进制转换为对象 作用:传输数据:状态保持(例如应用程序记忆上次关闭时的状态) 注:被序列化对象的类的所有成员也必须被标记为可序列化特性.该类 ...
- iOS开发之使用 infer静态代码扫描工具
infer是Facebook 的 Infer 是一个静态分析工具.可以分析 Objective-C, Java 或者 C 代码,报告潜在的问题. 任何人都可以使用 infer 检测应用,可以将严重的 ...
- 「CSP-S模拟赛」2019第一场
目录 T1 小奇取石子 题目 考场思路 正解 T2 「CCO 2017」专业网络 题目 考场思路 题解 T3 「ZJOI2017」线段树 题目 考场思路 正解 这场考试感觉很奇怪. \(T1.T2\) ...