PAT-A1091

#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;
struct pnode{
	int x,y,z;
}node, front;
int m, n, L , T, ans=0, matrix[1300][130][62];
bool inq[1300][130][62]={false};
int xx[6]={0,0,0,0,1,-1};
int yy[6]={0,0,1,-1,0,0};
int zz[6]={1,-1,0,0,0,0};
bool judge(int x, int y, int z){
	if(x>=m||x<0||y>=n||y<0||z>=L||z<0)return false;
	if(matrix[x][y][z]==0||inq[x][y][z]==true)return false;
	if(matrix[x][y][z]==1&&inq[x][y][z]==false)return true;
	else return true;
}
int BFS(int x, int y, int z){
	int ii, newx, newy, newz, total=0;
	queue<pnode> que;
	node.x=x;node.y=y;node.z=z;
	que.push(node);
	inq[x][y][z]=true;
		while(!que.empty()){
			front=que.front();
			que.pop();
            total++;
			for(ii=0;ii<6;ii++){
				newx=front.x+xx[ii];
				newy=front.y+yy[ii];
				newz=front.z+zz[ii];
				if(judge(newx,newy,newz)){
					node.x=newx;node.y=newy;node.z=newz;
					inq[newx][newy][newz]=true;
					que.push(node);
				}
			}
	    }//while
		if(total>=T)return total;
		else return 0;
}
int main(){
int x, y, z;
scanf("%d%d%d%d",&m,&n,&L,&T);
for(z=0;z<L;z++)
	for(x=0;x<m;x++)
		for(y=0;y<n;y++)
			scanf("%d",&matrix[x][y][z]);
for(z=0;z<L;z++)
	for(x=0;x<m;x++)
		for(y=0;y<n;y++){
			if(matrix[x][y][z]==1&&inq[x][y][z]==false)
				ans+=BFS(x,y,z);
		
		}
printf("%d\n",ans);

return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值