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

  • 相关阅读:
    基于最大最小距离的分类数目上限K确定的聚类方法
    diff函数(matlab)
    CreateThread线程函数
    套接字基础
    基于TCP套接字实现的简单Demo
    使用httpwatch抓包
    TLV----Demo讲解
    关于位图边缘的检测定位
    从txt中读入数据到数组中(fscanf)
    C语言运算符的优先级
  • 原文地址:https://www.cnblogs.com/james1207/p/3260332.html
Copyright © 2011-2022 走看看