forked from chr4ss1/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBITMAP.cpp
More file actions
85 lines (70 loc) · 1.6 KB
/
BITMAP.cpp
File metadata and controls
85 lines (70 loc) · 1.6 KB
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
#include <stdio.h>
#include <utility>
#include <queue>
using namespace std;
int width;
int height;
int bitmap[183][183] = {0};
char visited[183][183] = {0};
int main()
{
int test_cases;
scanf("%d", &test_cases);
while(test_cases--)
{
scanf("%d %d", &height, &width);
queue<pair<int, int> > que;
for(int h = 0; h < height; h++)
{
char f;
scanf("%c", &f);//RN
for(int w = 0; w < width; w++)
{
scanf("%c", &bitmap[h][w]);
bitmap[h][w] -= '0';
if(bitmap[h][w] == 1)
{
visited[h][w] = 1;
que.push(make_pair(w, h));
}
}
}
while(!que.empty())
{
pair<int, int> element = que.front();
que.pop();
int w = element.first;
int h = element.second;
visited[h][w] = 1;
const int possibleMoves = 4;
int moves[possibleMoves][2] = {{w + 1, h}, {w - 1, h}, {w, h + 1}, {w, h - 1}};
for(int j = 0; j < possibleMoves; j++)
{
int possibleMoveX = moves[j][0];
int possibleMoveY = moves[j][1];
// should we check it out?! YES!
if(possibleMoveX >= 0 && possibleMoveY >= 0 && possibleMoveX < width && possibleMoveY < height
&& visited[possibleMoveY][possibleMoveX] == 0)
{
bitmap[possibleMoveY][possibleMoveX] = bitmap[h][w] + 1;
que.push(make_pair(possibleMoveX, possibleMoveY));
visited[possibleMoveY][possibleMoveX] = 1;
}
}
}
for(int k = 0; k < height; k++)
{
for(int v = 0; v < width; v++)
{
printf("%d ", bitmap[k][v] - 1);
bitmap[k][v] = 0;
}
printf("\n");
}
// reset to zero
for(int v = 0; v < 183; v++)
for(int k = 0; k < 183; k++)
visited[v][k] = 0;
}
return 0;
}