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

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

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

》》》》《《《《

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

#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. HDU 5952 [DFS]

    题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=5952] 题意:给出一张无向图,然后判断这张图中一共有多少个不同的大小为S的完全图,并且保证每个点的度 ...

  2. 「WC2018即时战略」

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

  3. 51nod1675 序列变换

    link 题意: 给定长为n的序列a,b,下标从1开始,问有多少对x,y满足gcd(x,y)=1且$a_{b_x}=b_{a_y}$? $n\leq 10^5.$ 题解: $a_{b_x}$和$b_{ ...

  4. 设计模式 -- 桥接模式(Bridge)

    写在前面的话:读书破万卷,编码如有神--------------------------------------------------------------------主要内容包括: 初始桥接模式 ...

  5. bzoj 3224 普通平衡树 vactor的妙用

    3224: Tyvj 1728 普通平衡树 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...

  6. Use a microcontroller to design a boost converter

    Boost converters, like other switchers, have traditionally received their control signals from a ded ...

  7. Make a printer-port EEPROM programmer and dongle

    You can easily use a PC's printer port for serial-EEPROM programming. You can use a device-programme ...

  8. U3D内存优化

    原创文章如需转载请注明:转载自风宇冲Unity3D教程学院                                                U3D内存优化   读了Hog关于内存管理文章 ...

  9. JAVA常见算法题(三十一)---冒泡排序

    package com.jege.spring.boot.hello.world; /** * java算法之冒泡排序<br> * 将数组按照从大到小的顺序排列<br> * * ...

  10. 取出html中指定id的元素的内容

    private void btnGet_Click(object sender, EventArgs e) { string PageUrl = "http://www.cnblogs.co ...