杭电OJ Robot Motion-1035

编程入门 行业动态 更新时间:2024-10-28 15:27:59

杭电<a href=https://www.elefans.com/category/jswz/34/1768308.html style=OJ Robot Motion-1035"/>

杭电OJ Robot Motion-1035

题目链接
Sample Input
3 6 5
NEESWE
WWWESS
SNWWWW
4 5 1
SESWE
EESNW
NWEEN
EWSEN
0 0

Sample Output
10 step(s) to exit
3 step(s) before a loop of 8 step(s)

思路:直接模拟就行了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
char direct[100][100], steps[100][100];
int vis[100][100];int main()
{int row, col, ent;while(scanf("%d %d",&row,&col) && row){scanf("%d",&ent);map<char,int> p;char st;int step = 0, r = 0, c = ent - 1, flag = 0;memset(vis,0,sizeof(vis));for(int i=0;i < row;i++){scanf("%s",direct[i]);}while(!vis[r][c]){step++;vis[r][c] = 1;steps[r][c] = step;switch(direct[r][c]){case 'N':r -= 1;break;case 'S':r += 1;break;case 'E':c += 1;break;case 'W':c -= 1;}if((r >= row || r < 0) || (c >= col || c < 0)){flag = 1;break;}}if(!flag){printf("%d step(s) before a loop of %d step(s)\n",steps[r][c]-1,step-steps[r][c]+1);}else{printf("%d step(s) to exit\n",step);}}return 0;
}

更多推荐

杭电OJ Robot Motion-1035

本文发布于:2023-07-28 17:50:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267557.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:OJ   杭电   Robot   Motion

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!