-
Notifications
You must be signed in to change notification settings - Fork 0
/
10kindsofpeople.cpp
96 lines (73 loc) · 1.99 KB
/
10kindsofpeople.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
93
94
95
96
//
// Created by Tony on 8/10/2021.
//
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
int R, C;
vector<string> grid;
vector<vector<bool>> used;
vector<vector<int>> dist;
int counter = 1;
struct point {
int x; int y;
};
int dx[4] = {0,0,-1,1};
int dy[4] = {1,-1,0,0};
bool inbounds(point a) {
return a.x >= 0 && a.x < R && a.y < C && a.y >= 0;
}
void floodfill(point start, char ID) {
used[start.x][start.y] = true;
dist[start.x][start.y] = counter;
for (int i = 0; i < 4; i++) {
point next{start.x+dx[i],start.y+dy[i]};
if (inbounds(next) && !used[next.x][next.y] && grid[next.x][next.y] == ID) {
used[next.x][next.y] = true;
dist[next.x][next.y] = counter;
floodfill(next,ID);
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> R >> C;
grid.assign(R,"");
used.assign(R,vector<bool>(C,false));
dist.assign(R,vector<int>(C,-1));
for (int i = 0; i < R; i++) {
cin >> grid[i];
}
int Q;
cin >> Q;
for (int i = 0; i < Q; i++) {
point start;
point end;
cin >> start.x >> start.y >> end.x >> end.y;
start.x--;start.y--;end.x--;end.y--;
if (!used[start.x][start.y]) {
floodfill(start,grid[start.x][start.y]);
}
counter++;
if (dist[start.x][start.y] != -1 && dist[start.x][start.y] == dist[end.x][end.y])
{
if (grid[start.x][start.y] == '0')
cout << "binary";
else if (grid[start.x][start.y] == '1')
cout << "decimal";
else
cout << "neither";
}
else
cout << "neither";
cout << endl;
}
// for (vector<int> i : dist) {
// for ( int j : i) {
// cout << j << " ";
// }
// cout << endl;
// }
}