算是搜索题吧。。。。
1 /* 2 hdu 1035 Robot Motion 3 简单题 虽然代码有些长 但是写起来简单,不费脑子 4 */ 5 #include <iostream> 6 #include <stdio.h> 7 #include <cstring> 8 using namespace std; 9 int p; 10 int m,n; 11 int a[15][15]; 12 char c[15][15]; 13 void fun(int x,int y) 14 { 15 p++; 16 if(x<0||x>=m) throw -2;//需先判断是否出界,否则WA 17 if(y<0||y>=n) throw -2; 18 if(a[x][y]==-1) 19 a[x][y]=p; 20 else 21 throw a[x][y]; 22 switch(c[x][y]) 23 { 24 case 'N': 25 fun(x-1,y); 26 break; 27 case 'E': 28 fun(x,y+1); 29 break; 30 case 'W': 31 fun(x,y-1); 32 break; 33 case 'S': 34 fun(x+1,y); 35 break; 36 } 37 38 } 39 int main() 40 { 41 42 while(scanf("%d %d",&m,&n)!=EOF) 43 { 44 if(m==0||n==0) 45 break; 46 memset(a,-1,sizeof(a)); 47 memset(c,'