L3-004 肿瘤诊断 (30 分)

简单BFS,注意数组越界。

#include <bits/stdc++.h>
using namespace std;
int table[65][1290][130], n, x, y;
int minvol = 0;
int ans = 0;
struct point{
	int xx;
	int yy;
	int zz;
	point(int a, int b, int c): xx(a), yy(b), zz(c){}
};
bool isok(int xx, int yy, int zz){
	if(xx < 0 || xx >= n || y < 0 || yy >= x || zz < 0 || zz >= y) return false;
	return true;
}
int main(){
	scanf("%d %d %d %d", &x, &y, &n, &minvol);
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < x; ++j)
			for(int k = 0; k < y; ++k)
				scanf("%d", &table[i][j][k]);
	queue<point> q;
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < x; ++j)
			for(int k = 0; k < y; ++k){
				if(1 == table[i][j][k]){
					int tempans = 0;
					q.push(point(i, j, k));
					while(!q.empty()){
						point temppoint = q.front();
						q.pop();
						if(!isok(temppoint.xx, temppoint.yy, temppoint.zz)) continue;
						if(1 == table[temppoint.xx][temppoint.yy][temppoint.zz]){
							table[temppoint.xx][temppoint.yy][temppoint.zz] = 0;
							tempans++;
							q.push(point(temppoint.xx + 1, temppoint.yy, temppoint.zz));
							q.push(point(temppoint.xx - 1, temppoint.yy, temppoint.zz));
							q.push(point(temppoint.xx, temppoint.yy + 1, temppoint.zz));
							q.push(point(temppoint.xx, temppoint.yy - 1, temppoint.zz));
							q.push(point(temppoint.xx, temppoint.yy, temppoint.zz + 1));
							q.push(point(temppoint.xx, temppoint.yy, temppoint.zz - 1));
						}
					}
					if(tempans >= minvol) ans += tempans;
				}
			}
	printf("%d\n", ans);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值