L3-004. 肿瘤诊断
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
陈越
在诊断肿瘤疾病时,计算肿瘤体积是很重要的一环。给定病灶扫描切片中标注出的疑似肿瘤区域,请你计算肿瘤的体积。
输入格式:
输入第一行给出4个正整数:M、N、L、T,其中M和N是每张切片的尺寸(即每张切片是一个M×N的像素矩阵。最大分辨率是1286×128);L(<=60)是切片的张数;T是一个整数阈值(若疑似肿瘤的连通体体积小于T,则该小块忽略不计)。
最后给出L张切片。每张用一个由0和1组成的M×N的矩阵表示,其中1表示疑似肿瘤的像素,0表示正常像素。由于切片厚度可以认为是一个常数,于是我们只要数连通体中1的个数就可以得到体积了。麻烦的是,可能存在多个肿瘤,这时我们只统计那些体积不小于T的。两个像素被认为是“连通的”,如果它们有一个共同的切面,如下图所示,所有6个红色的像素都与蓝色的像素连通。
Figure 1
输出格式:
在一行中输出肿瘤的总体积。
输入样例:3 4 5 2 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 0 1 1 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0输出样例:
26
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
int mp[1290][130][65];
bool vis[1290][130][65];
int fx[6]={0,0,0,0,1,-1};
int fy[6]={0,0,1,-1,0,0};
int fz[6]={1,-1,0,0,0,0};
int ans;
struct AA{
int a,b,c;
AA(int aa,int bb,int cc):a(aa),b(bb),c(cc){}
};
int m,n,l,T;
inline bool check(int x,int xx){
if(x>=0&&x<xx)return true;
return false;
}
void bfs(int x,int y,int z){
vis[x][y][z]=1;
queue<AA> q;
q.push(AA(x,y,z));
int s=0;
while(!q.empty()){
AA t=q.front();
s++;
q.pop();
for(int i=0;i<6;i++){
int xx=t.a+fx[i];
int yy=t.b+fy[i];
int zz=t.c+fz[i];
if(!check(xx,m)||!check(yy,n)||!check(zz,l))
continue;
if(!vis[xx][yy][zz]&&mp[xx][yy][zz]){
q.push(AA(xx,yy,zz));vis[xx][yy][zz]=1;
}
}
}
if(s>=T)ans+=s;
}
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",&mp[i][j][k]);
memset(vis,0,sizeof(vis));
ans=0;
for(int k=0;k<l;k++)
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
if(!vis[i][j][k]&&mp[i][j][k])
bfs(i,j,k);
printf("%d\n",ans);
}