标签:black ble mem void tput ane init copy continue
1 /* 2 Name: hdu--1312--Red and Black 3 Copyright: ?2017 日天大帝 4 Author: 日天大帝 5 Date: 30/04/17 19:19 6 Description: dfs 7 */ 8 #include<iostream> 9 #include<cstring> 10 using namespace std; 11 void dfs(int,int); 12 char map[30][30]; 13 int w,h,ans; 14 int x,y; 15 int dir[4][2] = {0,1,0,-1,1,0,-1,0}; 16 int main(){ 17 ios::sync_with_stdio(false); 18 19 while(cin>>w>>h,w||h){ 20 memset(map,0,sizeof(map)); 21 ans = 0; 22 for(int i=0; i<h; ++i){ 23 cin>>map[i]; 24 for(int j=0; j<w; ++j){ 25 if(map[i][j] == ‘@‘){ 26 x = i;y = j; 27 } 28 } 29 } 30 dfs(x,y); 31 cout<<ans<<endl; 32 } 33 return 0; 34 } 35 void dfs(int x,int y){ 36 ans++; 37 for(int i=0; i<4; ++i){ 38 int xx = x + dir[i][0]; 39 int yy = y + dir[i][1]; 40 if(xx<0 || yy<0 ||xx >=h|| yy>=w|| map[xx][yy] != ‘.‘)continue; 41 map[xx][yy] = ‘#‘; 42 dfs(xx,yy); 43 } 44 }
hdu--1312--Red and Black (dfs)
标签:black ble mem void tput ane init copy continue
原文地址:http://www.cnblogs.com/rtdd/p/6790309.html