#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int n,m,l,t;
int d[1290][190][61];
int visited[1290][190][61];
struct node{
int x;
int y;
int z;
};
int X[6]={0,0,-1,1,0,0};
int Y[6]={1,-1,0,0,0,0};
int Z[6]={0,0,0,0,-1,1};
bool judge(int x,int y,int z){
if(x<0||x>=n||y<0||y>=m||z<0||z>=l) return false;
if(!d[x][y][z]||visited[x][y][z]) return false;
return true;
}
int bfs(int x,int y,int z){
queue<node>q;
int result=0;
visited[x][y][z]=1;
node n1;
n1.x=x;
n1.y=y;
n1.z=z;
q.push(n1);
while(!q.empty()){
node top=q.front();
q.pop();
result++;
for(int i=0;i<6;i++){
int newX=top.x+X[i];
int newY=top.y+Y[i];
int newZ=top.z+Z[i];
if(judge(newX,newY,newZ)){
node node1;
node1.x=newX,node1.y=newY,node1.z=newZ;
visited[newX][newY][newZ]=1;
q.push(node1);
}
}
}
if(result>=t) return result;
return 0;
}
int main(){
cin>>n>>m>>l>>t;
for(int z=0;z<l;++z){
for(int x=0;x<n;++x){
for(int y=0;y<m;++y){
scanf("%d",&d[x][y][z]);
visited[x][y][z]=0;
}
}
}
int total=0;
for(int z=0;z<l;++z){
for(int x=0;x<n;++x){
for(int y=0;y<m;++y){
if(d[x][y][z]&&!visited[x][y][z]){
int k=bfs(x,y,z);
total+=k;
}
}
}
}
cout<<total;
}```
PAT甲级1091Acute Stroke
最新推荐文章于 2023-01-25 17:21:34 发布