A1091 Acute Stroke (30 分)

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
struct Node{
	int x, y, z;
};
int M, N, L, T;
int regin[1300][130][65];
int nextx[] = {-1, 1, 0, 0, 0, 0};
int nexty[] = {0, 0, -1, 1, 0, 0};
int nextz[] = {0, 0, 0, 0, -1, 1};
int legal(int x, int y, int z){
	return x >= 0 && x < M &&
		   y >= 0 && y < N &&
		   z >= 0 && z < L;
}
int bfs(int x, int y, int z){
	int con = 1;
	regin[x][y][z] = 0;
	Node next;
	next.x = x; next.y = y; next.z = z;
	queue<Node> q;
	q.push(next);
	while(!q.empty()){
		Node temp = q.front();
		q.pop();
		int x1, y1, z1;	
		for(int i = 0; i < 6; i++){
			x1 = temp.x + nextx[i];
			y1 = temp.y + nexty[i];
			z1 = temp.z + nextz[i];
			if(legal(x1, y1, z1) && regin[x1][y1][z1] == 1){
				regin[x1][y1][z1] = 0;
				con++;
				next.x = x1; next.y = y1; next.z = z1;
				q.push(next);
			}
		}	
	}
	return con;
}
int main(){	
	scanf("%d %d %d %d", &M, &N, &L, &T);
	for(int k = 0; k < L; k++){
		for(int i = 0; i < M; i++){
			for(int j = 0; j < N; j++){
				scanf("%d", &regin[i][j][k]);
			}
		}
	}
	int ans = 0, con;
	for(int k = 0; k < L; k++){
		for(int i = 0; i < M; i++){
			for(int j = 0; j < N; j++){
				if(regin[i][j][k] == 1){
					con = bfs(i, j, k);
					ans += (con >= T ? con : 0);
				}
			}
		}
	}	
	printf("%d\n", ans);
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值