天梯题集——肿瘤诊断(三维bfs)
发布时间
阅读量:
阅读量
肿瘤诊断


望题兴叹,就害怕了
实现代码
#include<bits/stdc++.h>
using namespace std;
int m, n, l, t, cnt;
int zl[70][130][1300];
bool judge[70][130][1300]={false};
int A[6] = {0, 0, 0, 0, 1, -1};
int B[6] = {0, 0, 1, -1, 0, 0};
int C[6] = {1, -1, 0, 0, 0, 0};
struct node{
int a, b, c;
}Node, top;
void bfs(int a, int b, int c){
Node = (node){a, b, c};
queue <node> q;
q.push(Node);
while(!q.empty()){
top = q.front();
q.pop();
cnt++;
for(int i=0; i<6; i++){
int da = top.a+A[i];
int db = top.b+B[i];
int dc = top.c+C[i];
if(da<=l&&da>0&&db<=m&&db>0&&dc<=n&&dc>0&&
!judge[da][db][dc]&&zl[da][db][dc]){
judge[da][db][dc] = true;
Node = (node){da, db, dc};
q.push(Node);
}
}
}
return;
}
int main(){
cin>>m>>n>>l>>t;
memset(zl, 0, sizeof(zl));
for(int i=1; i<=l; i++)
for(int j=1; j<=m; j++)
for(int k=1; k<=n; k++)
cin>>zl[i][j][k];
int sum=0;
for(int i=1; i<=l; i++)
for(int j=1; j<=m; j++)
for(int k=1; k<=n; k++){
if(zl[i][j][k]&&!judge[i][j][k]){
cnt = 0;
judge[i][j][k]=true;
bfs(i, j, k);
if(cnt>=t) sum += cnt;
}
}
cout<<sum<<endl;
return 0;
}
全部评论 (0)
还没有任何评论哟~
