A1091
#include<iostream>
#include<queue>
using namespace std;
int data[1290][130][61];
bool inq[1290][130][61]={false};
struct node
{
int x;
int y;
int z;
}Node;
int ans=0;
int xx[6]={1,-1,0,0,0,0};
int yy[6]={0,0,1,-1,0,0};
int zz[6]={0,0,0,0,1,-1};
int m,n,l,T;
bool judge(int x, int y, int z)
{
if(x<0 || x>=m || y<0 || y>=n || z<0 || z>=l)
return false;
if(inq[x][y][z]==true || data[x][y][z]==0)
return false;
return true;
}
int BFS(int x, int y, int z)
{
Node.x=x;
Node.y=y;
Node.z=z;
inq[x][y][z]=true;
queue<node> q;
q.push(Node);
int ans=0;
while(!q.empty())
{
node top=q.front();
q.pop();
for(int i=0; i<6; i++)
{
int newX=top.x+xx[i];
int newY=top.y+yy[i];
int newZ=top.z+zz[i];
if(judge(newX,newY,newZ))
{
inq[newX][newY][newZ]=true;
Node.x=newX;
Node.y=newY;
Node.z=newZ;
q.push(Node);
}
}
ans++;
}
if(ans>=T)
return ans;
else
return 0;
}
int main()
{
cin >> m >> n >> l >> T;
int all=0;
for(int z=0; z<l; z++)
for(int i=0; i<m; i++)
for(int j=0; j<n; j++)
{
cin >> data[i][j][z];
}
int ans=0;
for(int z=0; z<l; z++)
for(int i=0; i<m; i++)
for(int j=0; j<n; j++)
{
if(inq[i][j][z]==false && data[i][j][z]==1)
{
all+=BFS(i,j,z);
}
}
cout << all;
return 0;
}
共有条评论 网友评论