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:wangbaobao at 2009-05-16 10:59:12 > /* > 对图中的#点看它4周有几个"." 就加上几个,在用dfs搜索就能求出周长 > */ > #include"iostream" > > using namespace std; > char map[30][30]; > int path[30][30]; > int num; > int r,c; > int dfs(int x,int y) > { > if(map[x][y]=='.'||path[x][y]==1) > return 1; > re > path[x][y]=1; > if(map[x+1][y]=='.') > num++; > if(map[x-1][y]=='.') > num++; > if(map[x][y-1]=='.') > num++; > if(map[x][y+1]=='.') > num++; > dfs(x+1,y); > dfs(x-1,y); > dfs(x,y+1); > dfs(x,y-1); > dfs(x+1,y-1); > dfs(x+1,y+1); > dfs(x-1,y-1); > dfs(x-1,y+1); > return num; > } > > int main() > { > int x,y; > while(cin>>r>>c>>x>>y) > { > memset(map,'.',sizeof(map)); > memset(path,0,sizeof(path)); > if(r==0&&c==0&&x==0&&y==0) > break; > > for(int i=1;i<=r;i++) > for(int j=1;j<=c;j++) > cin>>map[i][j]; > num=0; > dfs(x,y); > cout<<num<<endl; > } > return 1; > } re Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator