-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21938.cpp
65 lines (57 loc) · 1.41 KB
/
21938.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
#include <iostream>
#include <memory.h>
#include <queue>
using namespace std;
typedef long long ll;
struct RGB{
int r,g,b;
};
void solve(){
int N, M; cin >> N >> M;
RGB rgbs[N][M];
int arr[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> rgbs[i][j].r >> rgbs[i][j].g >> rgbs[i][j].b;
}
}
int T; cin >> T;
queue<pair<int,int>> q;
bool visited[N][M]; memset(visited, false, sizeof(visited));
int result = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (rgbs[i][j].r+rgbs[i][j].g+rgbs[i][j].b >= T*3) {
arr[i][j]=255;
} else arr[i][j] = 0;
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (arr[i][j]==255 && !visited[i][j]) {
result++;
q.push({i,j});
int xxxx[]= {-1,1,0,0};
int yyyy[]= {0,0,-1,1};
while (q.size()) {
auto [x,y]=q.front(); q.pop();
visited[x][y] = true;
for (int i = 0; i < 4; i++) {
int nx = x + xxxx[i];
int ny = y + yyyy[i];
if (nx < 0 || ny < 0 || nx >= N || ny >= M) continue;
if (arr[nx][ny] ==0 || visited[nx][ny]) continue;
visited[nx][ny]=true;
q.push({nx,ny});
}
}
}
}
}
cout << result;
}
int main (){
cin.tie(0) -> sync_with_stdio(0);
solve();
return 0;
}