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

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

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

》》》》《《《《

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

#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. Failed to add VMware DC to zone due to : This DC is being managed by other CloudStack deployment.

    1.下载VMware-PowerCLI 2.安装VMware-PowerCLI 安装过程中会重复重启,请确认重启,不要设置稍后手动重启. 3.在开始,菜单中选择 vmware ->VMware ...

  2. (bc 1001) hdu 6015 skip the class

    Skip the Class Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  3. 【WIN10】Bind、Binding與Converter的使用

    Demo源碼下載:http://yunpan.cn/cHuCmI4NK4xwr  访问密码 8201 1.Bind Bind的使用方式是: <Button Content="{x:Bi ...

  4. HDU 1213(并查集)

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. 【UOJ 34】 多项式乘法 (FFT)

    [题意] 给你两个多项式,请输出乘起来后的多项式. 先打一个递归版本的模板... #include<cstdio> #include<iostream> #include< ...

  6. bzoj 1009: [HNOI2008]GT考试 -- KMP+矩阵

    1009: [HNOI2008]GT考试 Time Limit: 1 Sec  Memory Limit: 162 MB Description 阿申准备报名参加GT考试,准考证号为N位数X1X2.. ...

  7. bzoj 2055: 80人环游世界 -- 上下界网络流

    2055: 80人环游世界 Time Limit: 10 Sec  Memory Limit: 64 MB Description     想必大家都看过成龙大哥的<80天环游世界>,里面 ...

  8. Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟

    A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...

  9. Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit

    Google Code Jam Qualification Round Africa 2010 Problem A. Store Credit https://code.google.com/code ...

  10. mybatis源码分析(4)----org.apache.ibatis.binding包

    1.  我们通过接口操作数据库时,发现相关的操作都是在org.apache.ibatis.binding下 从sqSessin 获取getMapper() SqlSession session = s ...