| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
1A水过/*
560
*/
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=500;
char map[maxn][maxn];
int vis[maxn][maxn];
int stp[maxn][maxn];
int n,m,st;
void go(int i,int j,int step)
{
if(vis[i][j]==0){
cout<<step-1<<" step(s) to exit"<<endl;
return;
}
if(vis[i][j]==1){
int pre=stp[i][j]-1;
int loop=step-stp[i][j];
cout<<pre<<" step(s) before a loop of "<<loop<<" step(s)"<<endl;
return;
}
vis[i][j]=1;
stp[i][j]=step;
switch(map[i][j]){
case 'N':i--;break;
case 'S':i++;break;
case 'E':j++;break;
case 'W':j--;break;
}
go(i,j,step+1);
}
int main()
{
while(cin>>n>>m>>st,n||m||st){
memset(vis,0,sizeof(vis));//0 wall
memset(stp,0,sizeof(stp));
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>map[i][j];
vis[i][j]=-1;
}
}
go(1,st,1);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator