-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
43 lines (42 loc) · 849 Bytes
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=25;
char g[N][N];
bool st[N][N];
int ans;
int n,m;
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
void dfs(int x,int y)
{
st[x][y]=true;
ans++;
for(int i=0;i<4;i++)
{
int a=x+dx[i],b=y+dy[i];
if(a<0||a>=n||b<0||b>=m)continue;
if(st[a][b])continue;
if(g[a][b]!='.')continue;
dfs(a,b);
}
}
int main()
{
while(cin>>m>>n,n||m) {
for (int i = 0; i < n; i++)cin >> g[i];
int x = 0, y = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (g[i][j] == '@') {
x = i, y = j;
break;
}
memset(st,0,sizeof st);
ans;
dfs(x,y);
}
cout<<ans<<endl;
return 0;
}