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

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

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

》》》》《《《《

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

#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. 初识Linux 基础操作

    Linux常用指令: 在Linux中如果不懂基础命令,在Linux中将寸步难行,下面是我在初学Linux系统时总结的一些基本命令. 1.基础命令 ls                          ...

  2. 【BZOJ 3996】 3996: [TJOI2015]线性代数 (最小割)

    3996: [TJOI2015]线性代数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1368  Solved: 832 Description 给 ...

  3. 51nod 1962区间计数(单调栈加二分)

    题目要求是求出两个序列中处于相同位置区间并且最大值相同的区间个数,我们最直观的感受就是求出每个区间的最大值,这个可以O(N)的求,利用单调栈求出每个数作为最大值能够覆盖的区间. 然后我们可以在进行单调 ...

  4. Codeforces 1037 H. Security

    \(>Codeforces \space 1037\ H. Security<\) 题目大意 : 有一个串 \(S\) ,\(q\) 组询问,每一次给出一个询问串 \(T\) 和一个区间 ...

  5. [BZOJ4247]挂饰(DP)

    当最终挂饰集合确定了,一定是先挂挂钩多的在挂挂钩少的. 于是按挂钩从大到小排序,然后就是简单的01背包. #include<cstdio> #include<algorithm> ...

  6. 【暴力】Gym - 100851A - Adjustment Office

    题意:给你一个n*n的矩阵,初始时,(x,y)的值为x+y.可能有两类操作,一类是对某一行求和,并将这一行置零:另一类是对某一列求和,并将这一列置零. 维护四个值:一个是列标号之和,一个是当前存在的列 ...

  7. YanghuiTriangle

    Demand 1 用实现循环队列 2 参考PPT用循环队列打印杨辉三角 3 用JDB或IDEA单步跟踪排队情况,画出队列变化图,包含自己的学号信息 4 把代码推送到代码托管平台 5 把完成过程写一篇博 ...

  8. April Fools Day Contest 2016 A. Da Vinci Powers

    A. Da Vinci Powers 题目连接: http://www.codeforces.com/contest/656/problem/A Description The input conta ...

  9. Codeforces Beta Round #80 (Div. 1 Only) D. Time to Raid Cowavans 分块

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

  10. VC中__int64的用法

    VCVC6.0的64位整数分别叫做__int64与unsigned __int64,其范围分别是[-2^63, 2^63)与[0,2^64),即-922337203685 4775808~922337 ...