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 |
Re:菜鸟 练习搜索 第二题In Reply To:菜鸟 练习搜索 第二题 Posted by:211550 at 2014-08-10 13:55:17 > > > > #include <iostream> > #include <algorithm> > #include <string> > #include <cstdio> > #include <cstring> > #include <cstdlib> > #include <cmath> > #include <vector> > #include<queue> > using namespace std; > #define lson ((root<<1)+1) > #define rson ((root<<1)+2) > #define MID ((l+r)>>1) > typedef long long ll; > typedef pair<int,int> P; > const int maxn=10005; > const int base=1000; > const int inf=999999; > int n,m; > char a[maxn][maxn]; > int dir[4][2]= {1,0,-1,0,0,1,0,-1}; > int cnt; > void dfs(int x,int y) > { > if(x<0||x>=n||y<0||y>=m)return ; > if(a[x][y]=='.') > { > cnt++; > a[x][y]='#'; > } > for(int i=0; i<4; i++) > { > int dx=x+dir[i][0]; > int dy=y+dir[i][1]; > if(a[dx][dy]!='#') > { > dfs(dx,dy); > } > } > } > int main() > { > int i,j,k,t; > int si,sj; > while(scanf("%d%d",&m,&n),n,m) > { > for(i=0; i<n; i++) > for(j=0; j<m; j++) > { > cin>>a[i][j]; > if(a[i][j]=='@') > { > si=i; > sj=j; > } > } > > cnt=1; > a[si][sj]='#'; > dfs(si,sj); > printf("%d\n",cnt); > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator