zoukankan      html  css  js  c++  java
  • hdu 1035 Robot Motion(dfs)

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

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

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

    》》》》《《《《

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


    #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) ",ans[sx][sy]-1,temp-ans[sx][sy]+1);
    else
    printf("%d step(s) to exit ",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

  • 相关阅读:
    [爬虫] js
    [爬虫] appium-移动端
    如何进行代码的重构
    重写与覆盖的区别
    解决C#中FileSystemWatcher类的Changed事件触发多次的问题
    关于sqlserver 2008 远程导入表数据
    css 选择器
    前端三剑客
    前端的概述
    元类作业
  • 原文地址:https://www.cnblogs.com/james1207/p/3260332.html
Copyright © 2011-2022 走看看