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

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

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

》》》》《《《《

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

#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. cf 633B A trivial problem

    Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an i ...

  2. 类命名空间与对象、实例的命名空间 and 面向对象的组合用法

    类命名空间与对象.实例的命名空间 创建一个类就会创建一个类的名称空间,用来存储类中定义的所有名字,这些名字称为类的属性 而类有两种属性:静态属性和动态属性 静态属性就是直接在类中定义的变量 动态属性就 ...

  3. 活动a 使用 启动为结果 方法 启动 活动 b, b什么都不做 并返回给a,a中的 在活动结果时候 回调 是否被执行?

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 活动a 使用 启动为结果 方法 启动 活动 b, b什么都不做 并返回给a,a中的 在活 ...

  4. The 2016 ACMICPC Asia Beijing Regional Contest

    A. Harmonic Matrix Counter (3/19) B. Binary Tree (1/14) C. Asa's Chess Problem (21/65) [ Problem ] 给 ...

  5. 【矩阵快速幂优化DP】【校内测试】

    实际上是水水题叻,先把朴素DP方程写出来,发现$dp[i]$实际上是$dp[i-k]-dp[i-1]$的和,而看数据范围,我们实际上是要快速地求得这段的和,突然就意识到是矩阵快速幂叻. 构建矩阵什么的 ...

  6. hdu 5207 Greatest Greatest Common Divisor 数学

    Greatest Greatest Common Divisor Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/ ...

  7. Codeforces Round #194 (Div. 1) B. Chips 水题

    B. Chips Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/333/problem/B D ...

  8. 不错的VS2010扩展——JSEnhancements,让js和css也折叠

    在Visaul Studio 2010中写js或css代码,缺少像写C#代码时的那种折叠功能,当代码比较多时,就很不方便. 今天发现,已经有VS2010扩展支持这个功能,它就是——JSEnhancem ...

  9. oc/object-c/ios哪种遍历NSArray/NSDictionary方式快?测试报告

    做app的时候,总免不了要多次遍历数组或者字典.究竟哪种遍历方式比较快呢?我做了如下测试:首先定义测试用宏: ? 1 2 3 4 5 6 7 8 9 #define MULogTimeinterval ...

  10. Circuit level-shifts ac signals

    AC signals can emanate from many sources, and many of these sources are incompatible with the most p ...