标签:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 30914 | Accepted: 16846 |
Description
Input
Output
Sample Input
6 9 ....#. .....# ...... ...... ...... ...... ...... #@...# .#..#. 11 9 .#......... .#.#######. .#.#.....#. .#.#.###.#. .#.#..@#.#. .#.#####.#. .#.......#. .#########. ........... 11 6 ..#..#..#.. ..#..#..#.. ..#..#..### ..#..#..#@. ..#..#..#.. ..#..#..#.. 7 7 ..#.#.. ..#.#.. ###.### ...@... ###.### ..#.#.. ..#.#.. 0 0
Sample Output
45 59 6 13
Source
#include <cstdio> int w, h; char s[25][25]; int cnt; bool inRoom(int x, int y) { return 0 <= x && x < h && 0 <= y && y < w; } void dfs(int x, int y) { if(inRoom(x, y) && s[x][y] == ‘.‘){ ++cnt; s[x][y] = ‘#‘; dfs(x-1, y); dfs(x+1, y); dfs(x, y-1); dfs(x, y+1); } } void solve() { int x, y; for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j) if(s[i][j] == ‘@‘){ x = i; y = j; s[i][j] = ‘.‘; goto END; } END: cnt = 0; dfs(x, y); printf("%d\n", cnt); } int main() { while(scanf("%d%d", &w, &h), w){ for(int i = 0; i < h; ++i) scanf("%s", s[i]); solve(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/inmoonlight/p/5746131.html