-
Notifications
You must be signed in to change notification settings - Fork 2
/
1012 - Guilty Prince.cpp
52 lines (52 loc) · 1.25 KB
/
1012 - Guilty Prince.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
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
int dirx[] = {1,-1,0,0};
int diry[] = {0,0,1,-1};
char str[22][22];
int vis[22][22];
int r,c;
int bfs(int x, int y)
{
int ans = 1;
vis[x][y] = 1;
queue<int> Q;
Q.push(x);Q.push(y);
while(!Q.empty()){
int x1 = Q.front();Q.pop();
int y1 = Q.front(); Q.pop();
for(int i=0; i<=3; i++){
int tx = x1+dirx[i];
int ty = y1+diry[i];
if(tx>=0 && tx<r && ty>=0 && ty<c){
if(vis[tx][ty]==0 && str[tx][ty] != '#'){
vis[tx][ty] = 1;
ans++;
Q.push(tx);
Q.push(ty);
}
}
}
}
return ans;
}
int main()
{
int tc;
scanf("%d",&tc);
for(int t=1; t<=tc; t++){
memset(vis, 0, sizeof vis);
scanf("%d%d",&c,&r);
int x=-1,y=-1;
for(int i=0; i<r; i++){
scanf("%s",str[i]);
for(int j = strlen(str[i])-1; j>=0 && x<0; j--){
if(str[i][j]=='@'){
x = i,y=j;
break;
}
}
}
printf("Case %d: %d\n",t,bfs(x,y));
}
return 0;
}