PATA 1091 Acute Stroke(30 分)解题报告

1091 Acute Stroke(30 分)

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 Specification:

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

Output Specification:

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

作者: CHEN, Yue

单位: 浙江大学

时间限制: 600 ms

内存限制: 64 MB

代码长度限制: 16 KB

 

本题的题意是,给定m*n的图,用0和1表示,1代表这个地方的脑部有问题,0则表示正常,脑袋是立体的,总共有L层。题目规定只有相邻的1多到一定数量才能算一个“坏死区域”,所谓的相邻,就是一个1的前后左右上下也有1,那就称这两个1是相邻的,本题要求你求出坏死区域的大小。

在输出中,先给出m*n,每一层扫描片的大小,l是层数,t则是“坏死区域”1数量的下界,然后依次给出脑部扫描的情况

解题思路:本题是一道非常明确的考察BFS的题目,所谓的坏死区域,我们只需要遇到1的时候,去用BFS的遍历他的周围结点,看是否还有1,对这期间的每一个1,再使用BFS,每遇到一个1,进行一次记数,当对这个区域遍历完之后,我们检查1的数量是否满足“坏死区域”下界t的要求,如果满足,就把这个区域的大小加入到答案中,遍历完整个扫描片之后,就能得到答案。为了防止结点的重复遍历,我们设置了visit数组来进行标记

关于BFS,可以查看BFS_study

 

AC代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
#include<stack>
#include<algorithm> 
#include<cmath>
using namespace std;
struct node{
	int x,y,z;
}temp;
int l,m,n,t;
int brain[1300][130][60];
bool visit[1300][130][60]={false};
int X[6]={1,0,0,-1,0,0};
int Y[6]={0,1,0,0,-1,0};
int Z[6]={0,0,1,0,0,-1};
bool judge(int x,int y,int z);
int BFS(int x,int y,int z);
int main()
{
	int ans=0;
	cin>>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++)
				cin>>brain[i][j][k];
	for(int k=0;k<l;k++)
		for(int i=0;i<m;i++)
			for(int j=0;j<n;j++)
				if(brain[i][j][k]==1&&visit[i][j][k]==false)
					ans+=BFS(i,j,k);
	cout<<ans;
	return 0;
}

bool judge(int x,int y,int z)
{
	if(x<0||x>=m||y<0||y>=n||z<0||z>=l)
		return false;
	if(brain[x][y][z]==0||visit[x][y][z]==true)
		return false;
	return true;
}

int BFS(int x,int y,int z)
{
	//cout<<"BFS is run"<<endl; 
	int cnt=0;
	temp.x=x;temp.y=y;temp.z=z;
	queue<node> q;
	q.push(temp);
	visit[x][y][z]=true;
	while(!q.empty())
	{
		node top=q.front();
		q.pop();
		cnt++;
		for(int i=0;i<6;i++)
		{
			int newx=top.x+X[i];
			int newy=top.y+Y[i];
			int newz=top.z+Z[i];
			if(judge(newx,newy,newz))
			{
				visit[newx][newy][newz]=true;
				temp.x=newx;temp.y=newy;temp.z=newz;
				q.push(temp);
			}
		}
	}
	//cout<<"The cnt is "<<cnt<<endl;
	if(cnt>=t)
		return cnt;
	else
		return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值