-
Notifications
You must be signed in to change notification settings - Fork 0
/
1091.cpp
52 lines (51 loc) · 1.1 KB
/
1091.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
#include <bits/stdc++.h>
using namespace std;
int m, n, l, t, sum = 0;//m是行,n是列,l是层
int matrix[1286][128][60];
int dx[6] = {0, 0, 1, -1, 0, 0};
int dy[6] = {1, -1, 0, 0, 0, 0};
int dz[6] = {0, 0, 0, 0, 1, -1};
struct coordinate{
int x, y, z;//x是行,y是列,x是层
coordinate(int xx, int yy, int zz){
x = xx;
y = yy;
z = zz;
}
};
void bfs(int x, int y, int z){
int cnt = 0;
queue<coordinate> q;
q.push(coordinate(x, y, z));
matrix[x][y][z] = 0;
while(!q.empty()){
coordinate u = q.front();
q.pop();
cnt++;
for(int i=0; i<6; i++){
x = u.x + dx[i];
y = u.y + dy[i];
z = u.z + dz[i];
if(x>=0&&x<m && y>=0&&y<n && z>=0&&z<l && matrix[x][y][z]==1){
q.push(coordinate(x, y, z));
matrix[x][y][z] = 0;
}
}
}
if(cnt >= t) sum += cnt;
}
int main(){
//freopen("input.txt", "r", stdin);
ios::sync_with_stdio(false);
cin>>m>>n>>l>>t;
for(int i=0; i<l; i++)
for(int j=0; j<m; j++)
for(int k=0; k<n; k++) cin>>matrix[j][k][i];
for(int i=0; i<l; i++)
for(int j=0; j<m; j++)
for(int k=0; k<n; k++){
if(matrix[j][k][i] == 1) bfs(j, k, i);
}
cout<<sum;
return 0;
}