题目描述
在诊断肿瘤疾病时,计算肿瘤体积是很重要的一环。给定病灶扫描切片中标注出的疑似肿瘤区域,请你计算肿瘤的体积。
C++ 代码
#include<bits/stdc++.h>
using namespace std;
int M,N,L,T;
bool s1[62][1288][130];///记录像素点
bool s2[62][1288][130];///记录像素点是否被访问过
struct Node{
int x,y,z;///像素点坐标
};
int single;///记录连续的像素块数
int sum=0;///记录总面积
int direction[6][3]={{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}};///记录六个方位
int main(){
cin>>M>>N>>L>>T;
int t;
///记录切片信息
for(int i=1;i<=L;i++){
for(int j=1;j<=M;j++){
for(int k=1;k<=N;k++){
scanf("%d",&t);
if(t)
s1[i][j][k]=true;
}
}
}
///诊断
struct Node n1,n2;
queue<struct Node>q;
for(int i=1;i<=L;i++){
for(int j=1;j<=M;j++){
for(int k=1;k<=N;k++){
single=0;
if(s1[i][j][k]&&!s2[i][j][k]){
s2[i][j][k]=true;
single++;
n1.z=i;
n1.x=j;
n1.y=k;
q.push(n1);
while(!q.empty()){
n1=q.front();
q.pop();
for(int l=0;l<6;l++){///访问当前点的上下左右前后的点
int nextx=n1.x+direction[l][0];
int nexty=n1.y+direction[l][1];
int nextz=n1.z+direction[l][2];
if(s1[nextz][nextx][nexty]&&!s2[nextz][nextx][nexty]){
n2.z=nextz;
n2.x=nextx;
n2.y=nexty;
q.push(n2);
single++;
s2[nextz][nextx][nexty]=true;
}
}
}
}
if(single>=T)
sum+=single;
}
}
}
cout<<sum;
return 0;
}
天梯赛进阶题就这吗,拿不到国二别玩了