地址:
题意:找可以到达的黑格子。
mark:dfs..
代码:
#includechar a[25][25];int sum;void ss(int w, int h, int x, int y){ if(y > 0 && a[x][y-1] == '.') { a[x][y-1] = '1'; sum++; ss(w, h, x, y-1); } if(x < h-1 && a[x+1][y] == '.') { a[x+1][y] = '1'; sum++; ss(w, h, x+1, y); } if(y < w-1 && a[x][y+1] == '.') { a[x][y+1] = '1'; sum++; ss(w, h, x, y+1); } if(x > 0 && a[x-1][y] == '.') { a[x-1][y] = '1'; sum++; ss(w, h, x-1, y); } return ;}int main(){ int w,h; int i,j,f,x,y; while(scanf("%d%d", &w, &h), w+h) { for(i = 0; i < h; i++) scanf("%s", a[i]); for(i = f = 0; i < h; i++) { if(f) break; for(j = 0; j < w; j++) if(a[i][j] == '@') {f = 1, x = i, y = j; break;} } a[x][y] = '1'; sum = 1; ss(w, h, x, y); printf("%d\n", sum); } return 0;}