Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
 User ID: Password:
Register

## Re:不过。。。为什么啊（附代码）

Posted by ACM_ddtc at 2010-08-04 11:25:52 on Problem 1573
In Reply To:这个测试用例很管用！ Posted by:BrainDeveloper at 2008-12-10 20:02:48
#include<iostream>
#include<fstream>
using namespace std;
#define MAX 12
char map[MAX][MAX];
int R,C;
int i,j;
int step[MAX][MAX];
void st(int &k)
{
switch(map[i][j])
{
case 'N':i--;break;
case 'S':i++;break;
case 'W':j--;break;
case 'E':j++;break;
}
if(i<0||j<0||i>R||j>C||step[i][j]!=-1)
return ;
step[i][j]=k++;
st(k);
}

int main()
{
int K,k;
//ifstream fin;
//fin.open("D:\\in.txt");
while(cin>>R>>C>>K&&R!=0&&C!=0&&K!=0)
{
k=1;
memset(step,-1,MAX*MAX);
for(int in=0;in<R;in++)
for(int jn=0;jn<C;jn++)
cin>>map[in][jn];
i=0;j=K-1;
step[i][j]=0;
st(k);
if(i<0||j<0||i>R||j>C)
{
cout<<k<<" step";
if(k!=1)
cout<<"(s)";
cout<<" to exit"<<endl;
}
else
{
k-=step[i][j];
cout<<step[i][j]<<" step";
if(step[i][j]!=1)
cout<<"(s)";
cout<<" before a loop of "<<k<<" step(s)"<<endl;
}

}
return 0;
}



Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator