-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfill.cc
More file actions
73 lines (63 loc) · 1.75 KB
/
Copy pathfill.cc
File metadata and controls
73 lines (63 loc) · 1.75 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
/*
Ibrahim Numanagić
Introduction to C++ and GDB
February 04, 2021
*/
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("test.txt", "r", stdin);
vector<string> lines;
int r, c;
cin >> r >> c; cin.ignore();
for (string l; getline(cin, l);) {
l.resize(c, ' ');
lines.push_back(l);
}
auto visited = vector<vector<char>>(r, vector<char>(c, 0));
auto fill = [&](int i, int j) -> pii {
auto dir = vector<pii>{{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
int zombie = 0, chick = 0;
queue<pii> q;
q.push({i, j});
visited[i][j] = 1;
while (!q.empty()) {
auto f = q.front();
q.pop();
if (lines[f.first][f.second] == 'z')
zombie++;
if (lines[f.first][f.second] == 'c')
chick++;
for (auto &d : dir) {
int ni = f.first + d.first, nj = f.second + d.second;
if (ni >= 0 && nj >= 0 && ni < r && nj < c && lines[ni][nj] != '#' &&
!visited[ni][nj]) {
q.push({ni, nj});
visited[ni][nj] = 1;
}
}
}
return {zombie, chick};
};
int zombie = 0, chick = 0, rooms = 0, solved_rooms = 0;
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
if (lines[i][j] != '#' && !visited[i][j]) {
auto zc = fill(i, j);
rooms++;
// printf("%d %d -- %d %d\n", i, j, zc.first, zc.second);
if (zc.second >= zc.first * 2)
chick += zc.second, solved_rooms++;
else
zombie += zc.first;
}
printf("rooms: %d\nzombie: %d, chick: %d\nsuccess: %.2lf%%\n", rooms, zombie,
chick, 100.0 * solved_rooms / double(rooms));
return 0;
}