PAT 1091

原创 2016年05月31日 09:59:49

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;
} 


版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

PAT 1091

1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B ...

1091. Acute Stroke (30)【搜索】——PAT (Advanced Level) Practise

题目信息1091. Acute Stroke (30)时间限制400 ms 内存限制65536 kB 代码长度限制16000 B One important factor to identify...

精选:深入理解 Docker 内部原理及网络配置

网络绝对是任何系统的核心,对于容器而言也是如此。Docker 作为目前最火的轻量级容器技术,有很多令人称道的功能,如 Docker 的镜像管理。然而,Docker的网络一直以来都比较薄弱,所以我们有必要深入了解Docker的网络知识,以满足更高的网络需求。

PAT甲级1091

1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B ...

PAT 1091. Acute Stroke (30)

1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B ...

PAT 1091. Acute Stroke (30)

三维图的连通路径问题,优雅的遍历方式

【PAT】1091. Acute Stroke (30)

One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re...

1091. Acute Stroke

本题的前4个case容易过,最后两个case有些难度。如果单纯递归,递归层次会很高从而导致栈溢出,若手动模拟栈实现,又会超出内存限额,于是考虑每次只遍历可连接的节点的个数不超过临界值t。如果节点块连接...

1091. Acute Stroke (30)

题目大意:计算连通域的大小,给出一个三维矩阵,先给出一个平面的矩阵依次向上叠加。计算其连通点大于阈值的个数。

PAT A 1091. Acute Stroke (30)

题目 One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core.  Given t...

PAT(Advance) 1091. Acute Stroke (30)

题意是在实难懂,其实就是就是包含上下左右前后的一块连通区域内的1的数量大于threshold DFS和BFS都可以,网上说DFS递归的话可能会爆栈,要写一个非递归的形式 我是用的BFS#inclu...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)