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 |
洪水又来了dfs0秒过!!!!!附代码!!!#include<stdio.h> char str[32][32]; int t=0,m,n; void Dfs(int x,int y) { // char c=str[x][y]; //str[x][y]='#'; if(str[x][y-1]=='.'&&x>=0&&x<m&&y-1>=0&&y-1<n) { t++; str[x][y-1]='#'; // printf("%d\n",t); Dfs(x,y-1); } if(str[x][y+1]=='.'&&x>=0&&x<m&&y+1>=0&&y+1<n) { t++; str[x][y+1]='#'; // printf("%d\n",t); Dfs(x,y+1); } if(str[x-1][y]=='.'&&x-1>=0&&x-1<m&&y>=0&&y<n) { str[x-1][y]='#'; t++; Dfs(x-1,y); // printf("%d\n",t); } if(str[x+1][y]=='.'&&x+1>=0&&x+1<m&&y>=0&&y<n) { t++; str[x+1][y]='#'; // Dfs(x+1,y); } // str[x][y]=c; return ; } int main() { int i,j,k,l,q,w,e,r,p; while(scanf("%d%d",&n,&m),n,m) { for(i=0;i<m;i++) scanf("%s",&str[i]); for(i=0;i<m;i++) { for(j=0;j<n;j++) if(str[i][j]=='@') break; if(str[i][j]=='@') break; } Dfs(i,j); printf("%d\n",t+1); t=0; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator