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

  • 相关阅读:
    产生6位的随机码
    用户输入注册的小程序
    进度条的小程序
    文件的相关操作---读写与修改
    字符串分割(C++) 转载
    C++ Stream与编码转换
    wxWidgets界面设计工具DialogBlocks(转载)
    WIN32窗口模板
    WTL对话框应用程序响应键盘消息
    常用网站
  • 原文地址:https://www.cnblogs.com/james1207/p/3260332.html
Copyright © 2011-2022 走看看