【剑指紫金港】1091 Acute Stroke 英语词汇&BFS

A 1091 Acute Stroke

题目链接

Problem Description

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.

Input

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.
1091

Output

For each case, output in a line the total volume of the stroke core.

Sample Input:

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

Sample Output:

26

题目大意

六分考英语阅读理解,四分考编程。给你一个三维空间,里边每个点的值要么为0、要么为1。求出三维空间里所有由1构成的连通域并统计每个连通域里1的个数,如果1的数量不小于T,则累加,最后输出所有连通域累加的结果。

解题思路

遍历三维空间,遇到一个1就对这个点展开广度优先搜索,每搜索到一个1就将这个点的值由1变为0 。

AC代码

#include <bits/stdc++.h>
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))
#define INF 0x3f3f3f3f
typedef long long ll;

int brain[60][1286][128],m,n,l,t,ans=0;
int go[6][3]={{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};

struct Node{
	int x,y,z;
	Node(int x,int y,int z):x(x),y(y),z(z){}
};

bool judge(int a, int b, int c){
	if(a<0 || a>=l || b<0 || b>=m || c<0 || c>=n){
		return false;
	}
	return true;
}

int bfs(int a, int b, int c){
	int sum=1;
	brain[a][b][c]=0;
	queue<Node> q;
	q.push(Node(a,b,c));
	while(!q.empty()){
		Node now=q.front();
		q.pop();
		int aa=now.x,bb=now.y,cc=now.z;
		for(int i=0; i<6; i++){
			int na=aa+go[i][0],nb=bb+go[i][1],nc=cc+go[i][2];
			if(judge(na,nb,nc)){
				if(brain[na][nb][nc]==1){
					brain[na][nb][nc]=0;
					q.push(Node(na,nb,nc));
					sum++;
				}
			}
		}
	}
	if(sum<t){sum=0;}
	return sum;
}

int main(int argc, char **argv){
	scanf("%d%d%d%d",&m,&n,&l,&t);
	for(int i=0; i<l; i++){
		for(int j=0; j<m; j++){
			for(int k=0; k<n; k++){
				scanf("%d",&brain[i][j][k]);
			}
		}
	}
	for(int i=0; i<l; i++){
		for(int j=0; j<m; j++){
			for(int k=0; k<n; k++){
				if(brain[i][j][k]){
					ans+=bfs(i,j,k);
				}
			}
		}
	}
	printf("%d",ans);
    return 0;
}  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

征服所有不服

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值