zoukankan      html  css  js  c++  java
  • POJ 1573 Robot Motion 模拟 难度:0

    #define ONLINE_JUDGE
    #include<cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    int A,B,sx,sy;
    char maz[101][101];
    int vis[101][101];
    const int dx[4]={0,1,0,-1};
    const int dy[4]={-1,0,1,0};
    
    int dir(char ch){
        if(ch=='N')return 0;
        else if(ch=='E')return 1;
        else if(ch=='S')return 2;
        return 3;
    }
    void print(int step){
        for(int s=1;s<step;s++){
            for(int i=0;i<A;i++){
                for(int j=0;j<B;j++){
                    if(vis[j][i]==s){
                        printf("vis[%d][%d]:%d
    ",j,i,vis[j][i]);
                    }
                }
            }
        }
    }
    void solve(){
        memset(vis,0,sizeof(vis));
        sx--;sy=0;
        int step=0;
        int fx,fy;
        while(!vis[sy][sx]&&sx>=0&&sx<A&&sy>=0&&sy<B&&++step){
            fx=sx;fy=sy;
            vis[sy][sx]=step;
            sx=dx[dir(maz[fy][fx])]+fx;
            sy=dy[dir(maz[fy][fx])]+fy;
        }
        if(sx<0||sy<0||sx>=A||sy>=B)printf("%d step(s) to exit
    ",step);
        else {
            printf("%d step(s) before a loop of %d step(s)
    ",vis[sy][sx]-1,step+1-vis[sy][sx]);
        }
    }
    int main(){
        #ifndef ONLINE_JUDGE
            freopen("output.txt","w",stdout);
        #endif // ONLINE_JUDGE
        while(scanf("%d%d%d",&B,&A,&sx)==3&&A&&B){
    
            for(int i=0;i<B;i++)scanf("%s",maz[i]);
            solve();
        }
        return 0;
    }
    

      

  • 相关阅读:
    django中的FBV和CBV
    RESTful
    REST
    18.前端路由router-08权限控制
    17.前端路由router-07keep-alive
    16.前端路由router-06动态路由
    15.前端路由router-05嵌套路由
    14.前端路由router-04编程式导航
    13.前端路由router-03路由参数
    java基础总结
  • 原文地址:https://www.cnblogs.com/xuesu/p/4754369.html
Copyright © 2011-2022 走看看