虽然做出来了,还是很失望的!!!

加油!!!还是慢慢来吧!!!

》》》》》》》》》》》》》》》》》》》》》》》》》》《《《《《《《《《《《《《《《《《《《《《《《《《《《

》》》》《《《《

很简单的一道题,一步步的走,走出矩阵则说明没有环,若走到已经走过的地方,说明有环,按格式输出结果即可!!!

#include<stdio.h>

#include<string.h>

int n,m,temp;

int ans[1010][1010];

char map[1010][1010];

void dfs(int sx,int sy)

{

while(sx>=0&&sx<n&&sy>=0&&sy<m&&map[sx][sy]!='o')


{


if(map[sx][sy]=='S')


{

//
temp++;


map[sx][sy]='o';


ans[sx][sy]=++temp;


sx++;


}


else if(map[sx][sy]=='N')


{


//temp++;


map[sx][sy]='o';


ans[sx][sy]=++temp;


sx--;


}


else if(map[sx][sy]=='E')


{


//temp++;


map[sx][sy]='o';


ans[sx][sy]=++temp;


sy++;


}


else if(map[sx][sy]=='W')


{


//temp++;


map[sx][sy]='o';


ans[sx][sy]=++temp;


sy--;


}


}


if(map[sx][sy]=='o')


printf("%d step(s) before a loop of %d step(s)\n",ans[sx][sy]-1,temp-ans[sx][sy]+1);


else


printf("%d step(s) to exit\n",temp);

}

int main()

{


int k,i;


while(scanf("%d %d %d",&n,&m,&k),n+m+k)


{


memset(ans,0,sizeof(ans));


for(i=0;i<n;i++)


scanf("%s",map[i]);


temp=0;


dfs(0,k-1);


}


return 0;

}

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1035

hdu 1035 Robot Motion(dfs)的更多相关文章

  1. HDOJ(HDU).1035 Robot Motion (DFS)

    HDOJ(HDU).1035 Robot Motion [从零开始DFS(4)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DF ...

  2. (step 4.3.5)hdu 1035(Robot Motion——DFS)

    题目大意:输入三个整数n,m,k,分别表示在接下来有一个n行m列的地图.一个机器人从第一行的第k列进入.问机器人经过多少步才能出来.如果出现了循环 则输出循环的步数 解题思路:DFS 代码如下(有详细 ...

  3. [ACM] hdu 1035 Robot Motion (模拟或DFS)

    Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. ...

  4. HDU 1035 Robot Motion(dfs + 模拟)

    嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1035 这道题比较简单,但自己一直被卡,原因就是在读入mp这张字符图的时候用了scanf被卡. ...

  5. 题解报告:hdu 1035 Robot Motion(简单搜索一遍)

    Problem Description A robot has been programmed to follow the instructions in its path. Instructions ...

  6. hdu 1035 Robot Motion(模拟)

    Problem Description A robot has been programmed to follow the instructions in its path. Instructions ...

  7. hdu1035 Robot Motion (DFS)

    Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  8. hdoj 1035 Robot Motion

    Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  9. HDOJ(HDU).1045 Fire Net (DFS)

    HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...

随机推荐

  1. 【BZOJ 2957】 2957: 楼房重建 (线段树)

    2957: 楼房重建 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1753  Solved: 841 Description 小A的楼房外有一大片施 ...

  2. 表白 代码 韩梦飞沙-画心.html

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 韩梦飞沙-画心.html <!DOCTYPE html> <html& ...

  3. 「WC2018即时战略」

    「WC2018即时战略」 题目描述 小 M 在玩一个即时战略 (Real Time Strategy) 游戏.不同于大多数同类游戏,这个游戏的地图是树形的.也就是说,地图可以用一个由 \(n\) 个结 ...

  4. HDU 5514 Frogs(容斥原理)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5514 [题目大意] m个石子围成一圈,标号为0~m-1,现在有n只青蛙,每只每次跳a[i]个石子, ...

  5. 【插头DP】BZOJ3125-city

    开学忙成狗,刷题慢如蜗牛…… [题目大意] 给出一个m*n的矩阵里面有一些格子为障碍物,一些格子只能上下通行,一些格子只能左右通行,一些格子上下左右都能通行.问经过所有非障碍格子的哈密顿回路个数. [ ...

  6. 修改npm仓库地址

    在C:\Users\Administrator文件夹下找到.npmrc 添加registry = http://registry.cnpmjs.org淘宝镜像地址,保存

  7. 实用在线小工具 -- Google URL Shortener

          实用在线小工具 -- Google URL Shortener 当你想分享一些你觉得有趣的东西,但是那个链接太长,以至于贴上去一大片.比如在微博上分享一张图片,然后贴上去图片的链接,url ...

  8. 读书笔记_Effective_C++_条款二十九:为“异常安全”而努力是值得的

    还是举书上的例子: void PrettyMenu::changeBackground(std::istream& imgSrc) { lock(&mutex); delete bgI ...

  9. iOS 本地消息推送机制

    转发自:https://www.jianshu.com/p/e347f999ed95     //已经废除的 http://blog.csdn.net/three_zhang/article/deta ...

  10. SQL Server 2008内存及I/O性能监控

    来源: it168  发布时间: 2011-04-12 11:04  阅读: 10820 次  推荐: 1   原文链接   [收藏]   以下均是针对Window 32位系统环境下,64位的不在下面 ...