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 |
哪位神牛有时间,帮忙看一下!谢谢啦!#include <stdlib.h> #include<stdio.h> #include<string.h> char gird[15][15]; int flag,gnum[15][15],cir[15][15]; int Dfs(int x,int y,int row,int col); /* * pku 1573 */ int main(int argc, char** argv) { int i,j,k,t,row,col,start,temp; freopen("test.in","r",stdin); while(scanf("%d%d%d",&row,&col,&start)!=EOF){ if(row==0&&col==0&&start==0)break; memset(gnum,0,sizeof(gnum)); for(i=0;i<row;i++){scanf("%s",gird[i]);} flag=0; temp=Dfs(0,start-1,row,col); if(temp==0){ printf("%d step(s) to exit\n",flag); } else printf("%d step(s) before a loop of %d step(s)\n",temp,flag-temp); // printf("%d\n",temp); } return (EXIT_SUCCESS); } int Dfs(int x,int y,int row,int col){ int i,j; if(gnum[x][y]) return gnum[x][y]; else if(x<0||x>row||y<0||y>col) return 0; else{ gnum[x][y]=flag; switch(gird[x][y]){ case 'N': flag++;x--; return Dfs(x,y,row,col); case 'S': flag++;x++; return Dfs(x,y,row,col); case 'W': flag++;y--; return Dfs(x,y,row,col); case 'E': flag++;y++; return Dfs(x,y,row,col); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator