我绝望.我检讨..模拟..
一直pe..提交若干次后才发现是格式里多了个空格.
以后这个pe我是记住了..
#include <iostream>
using namespace std;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int n,m,x,y,u;
char ch[11][11];
bool hash[11][11];
int st[11][11];
void dfs(int x,int y,int step)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
st[x][y]=step;
hash[x][y]=true;
switch(ch[x][y])
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
case 'N':x--;break;
case 'E':y++;break;
case 'W':y--;break;
case 'S':x++;break;
default:break;
}
if (x<1||y<1||x>n||y>m)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
cout<<step<<" step(s) to exit"<<endl;
return;
}
if (hash[x][y])
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
cout<<st[x][y]-1<<" step(s) before a loop of "<<step-st[x][y]+1<<" step(s)"<<endl;
return;
}
dfs(x,y,step+1);
}
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
while(1)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
cin>>n>>m>>u;
if (n==0&&m==0&&u==0) break;
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
cin>>ch[i][j];
hash[i][j]=false;
}
// memset(hash,0,sizeof(hash));
dfs(1,u,1);
}
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)