find my world

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

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

#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

2017-01-28 20:55:44

#### 1091. Acute Stroke (30)-PAT甲级真题（广度优先搜索）

2016-08-21 14:57:41

#### 【PAT】1091. Acute Stroke (30)

2015-11-03 14:35:46

#### 浙大PAT advanced level 1001--1091答案代码

2015年10月02日 71KB 下载

#### 同步故障Last_Errno: 1091

2015-07-01 09:23:07

#### 51nod 1091 线段的重叠 贪心

2016-06-07 18:16:26

#### poj1091跳蚤---------容斥

2012-08-12 10:14:15

#### 杭电ACM----1091

2016-09-25 19:55:26

#### 51nod-1091 . 线段的重叠

2014-09-27 08:24:13

#### 杭电acm1091 A+B for Input-Output Practice (III)

2012-08-02 22:01:49

PAT 1091