-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1012 - Guilty Prince.cpp
92 lines (80 loc) · 1.79 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define EPS 0.00000001
#define PI 2*acos(0.0)
#define MOD 1000000007
#define ck(XX) cout<<XX<<endl
#define set(XX,POS) XX|(1<<POS)
#define reset(XX,POS) XX&(~(1<<POS))
#define check(XX,POS) (bool)(XX&(1<<POS))
#define toggle(XX,POS) (XX^(1<<POS))
#define Fin freopen("input.txt","r",stdin)
#define Fout freopen("output.txt","w",stdout)
#define MS(ARRAY,VALUE) memset(ARRAY,VALUE,sizeof(ARRAY))
#define RT printf("Run Time : %0.3lf seconds\n", clock()/(CLOCKS_PER_SEC*1.0))
#define valid(X,Y,R,C) X>=0 && X<R && Y>=0 && Y<C
int fr[] = {1,-1,0,0};
int fc[] = {0,0,1,-1};
int r,c;
char cell[22][22];
int visited[22][22];
int cnt;
struct node{
int row;
int col;
};
void bfs(int sr, int sc)
{
node n;
n.row = sr;
n.col = sc;
queue <node> Q;
visited[sr][sc] = 1;
Q.push(n);
while(!Q.empty())
{
node u = Q.front();
Q.pop();
for(int i=0; i<4; i++)
{
int nr=u.row+fr[i];
int nc=u.col+fc[i];
if(valid(nr,nc,r,c) && cell[nr][nc] == '.' && visited[nr][nc] == 0)
{
node t;
t.row = nr;
t.col = nc;
Q.push(t);
visited[nr][nc] = 1;
cnt++;
}
}
}
return;
}
int main()
{
//Fin;
int tc, cn=0;
int sr,sc;
cin >> tc;
while(tc--)
{
cnt = 1;
MS(visited,0);
MS(cell,0);
scanf("%d%d",&c,&r);
for(int i=0; i<r; i++)
{
for(int j=0; j<c; j++)
{
cin >> cell[i][j];
if(cell[i][j] == '@') {sr=i;sc=j;}
}
}
bfs(sr,sc);
printf("Case %d: %d\n",++cn, cnt);
}
return 0;
}