POJ_1573题解
来源:互联网 发布:基于栈的列表 java 编辑:程序博客网 时间:2024/05/18 03:48
http://poj.org/problem?id=1573
此题就是个简单的模拟题,用模拟法就可以水过。
//Memory:136 Time :0ms#include<cstdio>#include<cstring>using namespace std;int r,c;char rmap[11][11];//储存地图int vis[11][11];//用于记录是否访问过并且记录步数int fx(char ch)//用于判断x的走向{ switch(ch) { case 'W':return -1; case 'N':return 0; case 'E':return 1; case 'S':return 0; }}int fy(char ch)//判断y的走向{ switch(ch) { case 'W':return 0; case 'N':return -1; case 'E':return 0; case 'S':return 1; }}int main(){ int sx,sy; int xi,yi; while(scanf("%d%d%d",&r,&c,&sx)==3) { getchar();//吸收回车 if(r==0&&c==0&&sx==0) break; memset(vis,0,sizeof vis); for(int i=1;i<=r;i++) { for(int j=1;j<=c;j++) scanf("%c",&rmap[i][j]); getchar();//吸收回车 } sy=1; xi=sx; yi=sy; vis[sy][sx]=1; while(1) { xi=sx+fx(rmap[sy][sx]); yi=sy+fy(rmap[sy][sx]); if(xi<1||xi>c||yi<1||yi>r)//若越界了则证明可以出去 { printf("%d step(s) to exit\n",vis[sy][sx]); break; } if(!vis[yi][xi])//若此格子还未走过,则走此格子 vis[yi][xi]=vis[sy][sx]+1; else //若此格子已经走过,则证明已经进入环路 { printf("%d step(s) before a loop of %d step(s)\n",vis[yi][xi]-1,vis[sy][sx]-vis[yi][xi]+1); break; } sx=xi; sy=yi; } }}
- POJ_1573题解
- poj_1573
- POJ_1573
- poj_1573 构造
- POJ_1573 简单dfs
- poj_1573 Robot Motion(简单模拟)
- 题解
- 题解
- 题解
- 题解
- 题解
- 题解
- 题解
- 题解
- 题解
- 题解
- 题解
- 题解~~~~
- UVA 662 Fast Food
- Actor Framework for Windows Azure
- Android开发 MeasureSpec介绍
- The last work of this year - 2012
- java annotation
- POJ_1573题解
- chrome学习
- SSL证书
- using vector to implement buffer
- CF Round#17
- 对成功游戏的看法
- 25.写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
- 26.左旋转字符串
- 有关Java内存溢出及内存消耗的小知识