Created
September 10, 2017 13:05
-
-
Save mi6112ogit/1b26b641b414b5d7ad4e3b7b75dee0a0 to your computer and use it in GitHub Desktop.
This file contains 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 <algorithm> | |
#include <utility> | |
#include <map> | |
#include <queue> | |
#include <string> | |
#include <vector> | |
#include <cstdio> | |
#include <cstring> | |
#include <cstdlib> | |
#include <ctime> | |
#include <cmath> | |
using namespace std; | |
#define FOR(i, j, k) for(int i = j; i < k; ++i) | |
#define rep(i, j) FOR(i, 0, j) | |
#define INF (1 << 30) | |
typedef long long ll; | |
typedef unsigned long long ull; | |
typedef pair<int, int> P; | |
typedef pair<int, P> Pi; | |
const int MOD = 1e9 + 7; | |
const int dy[]={0, 0, 1, -1}; | |
const int dx[]={1, -1, 0, 0}; | |
template <class T> void chmin(T& a, const T& b) { a = min(a, b); } | |
template <class T> void chmax(T& a, const T& b) { a = max(a, b); } | |
int w, h, res = 0; | |
string s[21]; | |
bool went[21][21]; | |
void dfs(int x, int y) { | |
++res; | |
went[y][x] = true; | |
rep(i, 4) { | |
int nx = x + dx[i], ny = y + dy[i]; | |
if(0 > nx || nx >= w || 0 > ny || ny >= h) continue; | |
if(s[ny][nx] == '#' || went[ny][nx]) continue; | |
dfs(nx, ny); | |
} | |
} | |
int main() { | |
cin.tie(0); | |
ios::sync_with_stdio(false); | |
while(scanf("%d %d", &w, &h), w | h) { | |
res = 0; | |
int sx, sy; | |
rep(i, h) cin >> s[i]; | |
rep(i, h) rep(j, w) { | |
if(s[i][j] == '@') sx = j, sy = i; | |
} | |
memset(went, 0, sizeof(went)); | |
dfs(sx, sy); | |
printf("%d\n", res); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment