题目
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to calculate the volume of the stroke core.
输入
Each input file contains one test case. For each case, the first line contains 4 positive integers: M, N, L and T, where M and N are the sizes of each slice (i.e. pixels of a slice are in an M×N matrix, and the maximum resolution is 1286 by 128); L (≤60) is the number of slices of a brain; and T is the integer threshold (i.e. if the volume of a connected core is less than T, then that core must not be counted).
Then L slices are given. Each slice is represented by an M×N matrix of 0's and 1's, where 1 represents a pixel of stroke, and 0 means normal. Since the thickness of a slice is a constant, we only have to count the number of 1's to obtain the volume. However, there might be several separated core regions in a brain, and only those with their volumes no less than T are counted. Two pixels are connected and hence belong to the same region if they share a common side, as shown by Figure 1 where all the 6 red pixels are connected to the blue one.
Figure 1
输出
For each case, output in a line the total volume of the stroke core.
样例输入
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
题意理解
给你一个脑部区域 1 是中风区域 0就是不是中风区域 然后这个区域是立体的 如果某个连通块是小于t的体积的话忽略不计 如果大于等于的话加入到总体积里面 最后输出总体积 我们这里用BFS实现Flood Fill 因为每个点只会遍历一次 所以是O(n)的算法复杂度 先输入n行m列的一个平面块 然后输入l层 然后输入一共有l层 然后是可以六个方向联通的 用BFS跑一遍Flood Fill即可 记得一定要看好数据量
代码
#include<bits/stdc++.h>
using namespace std;
const int N=150,M=1310,K=110;
int n,m,l,t;
int ans;
int g[K][M][N];
bool st[K][M][N];
int dx[6]={1,-1,0,0,0,0};
int dy[6]={0,0,1,-1,0,0};
int dz[6]={0,0,0,0,1,-1};
typedef struct Node{
int x,y,z;
}Node;
bool check(Node no){
if(no.x>=1&&no.x<=l&&no.y>=1&&no.y<=n&&no.z>=1&&no.z<=m)return 1;
else return 0;
}
int bfs(Node no){
queue<Node>q;
q.push(no);
int nu=0;
st[no.x][no.y][no.z]=1;
while(q.size()){
auto te=q.front();
q.pop();
nu++;
for(int i=0;i<6;i++){
int a=te.x+dx[i],b=te.y+dy[i],c=te.z+dz[i];
Node ne={a,b,c};
if(check(ne)&&!st[a][b][c]&&g[a][b][c]){
q.push(ne);
st[a][b][c]=1;
}
}
}
return nu;
}
int main(){
scanf("%d%d%d%d",&n,&m,&l,&t);
for(int i=1;i<=l;i++){
for(int j=1;j<=n;j++){
for(int k=1;k<=m;k++){
scanf("%d",&g[i][j][k]);
}
}
}
for(int i=1;i<=l;i++){
for(int j=1;j<=n;j++){
for(int k=1;k<=m;k++){
if(g[i][j][k]&&!st[i][j][k]){
int T=bfs({i,j,k});
if(T>=t)ans+=T;
}
}
}
}
printf("%d\n", ans);
return 0;
}