Last active
December 18, 2015 05:48
-
-
Save Leko/5734881 to your computer and use it in GitHub Desktop.
AOJ 1130 Red and Black
Time Limit : 1 sec, Memory Limit : 65536 KB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 縦型探索 | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
int w, h; | |
int mx[] = {0, 0, -1, 1}; | |
int my[] = {-1, 1, 0, 0}; | |
int dfs(int x, int y, vector<string> &v) { | |
int cnt = 1; | |
for ( int i = 0; i < 4; i++ ) { | |
int nx = x + mx[i], ny = y + my[i]; | |
if ( 0 <= nx && nx < w && 0 <= ny && ny < h && v[ny][nx] == '.' ) { | |
v[ny][nx] = '#'; | |
cnt += dfs(nx, ny, v); | |
} | |
} | |
return cnt; | |
} | |
int main() { | |
while ( true ) { | |
int x, y; | |
cin >> w >> h; | |
if ( w == 0 && h == 0 ) break; | |
vector<string> v(h); | |
for ( int i = 0; i < h; i++ ) { | |
cin >> v[i]; | |
for ( int j = 0; j < v[i].size(); j++ ) { | |
if ( v[i][j] == '@' ) { | |
y = i; | |
x = j; | |
} | |
} | |
} | |
cout << dfs(x, y, v) << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment