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

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

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)

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