一介

find my world

PAT 1091

1091. Acute Stroke (30)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

分析:题目太抽象了,开了很多遍,就是说脑袋里有切片,给了L个每个为m*n的矩阵,最大不超过1280*128,最高不超过60;

        然后关键之处是,如果某个点为1,则找出该店3维空间内所有是1的点,如果他们的总和大于T,则被录入;

一开始看见还以为是每一列大于T,就ok;这里借鉴了 此去经年 的代码,关键是三维空间的bfs;

#include <iostream>
#include <vector>
#include <algorithm>
#include <map> 
#include <queue>
#include <stdio.h>
using namespace std;
int m,n,l,t;
int total=0;
int matrix[1286][128][60];  
int xx[6] = {1,-1,0,0,0,0};  
int yy[6] = {0,0,1,-1,0,0};  
int zz[6] = {0,0,0,0,1,-1};  
struct node{  
    int x, y, z;  
    node(int _x, int _y, int _z){  
        x=_x; y=_y; z=_z;  
}  
};
void bfs(int x,int y,int z)
{
	queue<node> q;
	q.push(node(x,y,z));
	matrix[x][y][z]=0;
	int cnt=1;
	while(!q.empty())
	{
		node no=q.front();
		for(int i=0;i<6;i++)
		{
			int tx=no.x+xx[i];
			int ty=no.y+yy[i];
			int tz=no.z+zz[i];
			if((tx>=0&&tx<m)&&ty>=0&&ty<n&&tz>=0&&tz<l&&matrix[tx][ty][tz]==1)
				{
					cnt++;
					matrix[tx][ty][tz]=0;
					q.push(node(tx,ty,tz));
				}
				
			}
				q.pop();
	}	
	if(cnt>=t)
	total+=cnt;
}    

int main()
{
	
//	int **a=new int *[m];
//	for(int i=0;i<m;i++)
//	a[i]=new int[n];
//	for(int i=0;i<m;i++)
//		for(int j=0;j<n;j++)
//		cin>>a[i][j]; 
	cin>>m>>n>>l>>t;
	for(int i=0;i<l;i++)
	{   
			for(int kk=0;kk<m;kk++)
			{		
					for(int j=0;j<n;j++)
				{
					scanf("%d",&matrix[kk][j][i]);
				}
			}
	}
			
	for(int i=0;i<m;i++)
		for(int j=0;j<n;j++)
		 for(int w=0;w<l;w++)
			 if(matrix[i][j][w]==1)
					bfs(i,j,w);
		
	
	cout<<total<<endl;
	return 0;
} 


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32274373/article/details/51543409
文章标签: 浙大PAT
个人分类: pat
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

PAT 1091

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭