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循环一直到机器人跳出来】
...
随机推荐
- Django Auth组件->扩展用户
Auth用户 1.声明用户表 djangauth/settings.py..............................AUTH_USER_MODEL = 'app01.UserInfo' ...
- 计算几何-BZOJ2618-凸包的交-HPI
This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. bzoj2618 ...
- sqli-libs(54-65关)
Less_54 Less-54:使用’’包裹 对输入的次数做了限制,必须在10次请求之内获取信息,否则会刷新表名 输入:?Id=1’ order by 3--+ 查看有多少列: 输入 ?id=-1 ...
- Codeforces Round #608 (Div. 2)D(贪心)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],b[],c[]; int u,v; ...
- MySQL存储引擎优化
如何在两种存储引擎中进行选择? ① 是否有事务操作?有,InnoDB. ②是否存储并发修改?有,InnoDB. ③是否追求快速查询,且数据修改较少?是,MyISAM. ④是否使用全文索引?如果不引用第 ...
- 蓝桥杯2016年省赛C/C++大学A组
网友年龄 某君新认识一网友. 当问及年龄时,他的网友说: "我的年龄是个2位数,我比儿子大27岁, 如果把我的年龄的两位数字交换位置,刚好就是我儿子的年龄" 请你计算:网友的年龄一 ...
- 归并非递归、快排递归及非递归的C++实现及时间效率对比。。
今天看剑指offer突然发现下学期都要去面试了,还没自己实现过快排非递归和归并非递归,这怎么能行呢,于是就写了一下. (虽然有点卡壳,又回去翻了下算导,还是顺利写出来了) 先放图: 一亿数据量: #p ...
- Django - 在settings配置终端打印SQL语句
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'console': { 'level': 'DE ...
- UIButton按钮的高亮状态颜色
首先是adjustsImageWhenHighlighted属性的正确使用: UIButton的adjustsImageWhenHighlighted属性是当UIButton设置了背景图片时,并且没有 ...
- 聊聊、Spring自动扫描
一.PathMatchingResourcePatternResolver 二.SimpleMetadataReaderFactory 三.实现(核心代码) private static final ...