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 |
因为是字符,所以要getchar!!!!(用scanf)输迷宫之前getchar一发,输入如一行getchar一次ac代码 #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; char Map[30][30]; int vis[27]; int m,n,cnt; int dr[]={-1,0,1,0}; int dc[]={0,1,0,-1}; void dfs(int r,int c,int depth) { vis[Map[r][c]-'A']=1; int flag=0; for(int i=0;i<=3;i++) { int new_r=r+dr[i]; int new_c=c+dc[i]; if(new_r>n||new_r<1||new_c<1||new_c>m) continue; if(!vis[Map[new_r][new_c]-'A']) { flag=1; dfs(new_r,new_c,depth+1); } } vis[Map[r][c]-'A']=0; if(!flag){cnt=max(cnt,depth);} } int main() { while(scanf("%d%d",&n,&m)==2) { cnt=0; memset(vis,0,sizeof(vis)); getchar(); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) scanf("%c",&Map[i][j]); getchar(); } dfs(1,1,1); printf("%d\n",cnt); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator