码迷,mamicode.com
首页 > 其他好文 > 详细

PAT1091Acute Stroke

时间:2015-02-25 11:31:55      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

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.

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

思想:正常的进队入队搜索的思路,需要注意的一点是此题是三维坐标。一维是横坐标,二维是纵坐标,三维是纵轴。
技术分享
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <queue>
 4 using namespace std;
 5 #define C 65
 6 #define A 1290
 7 #define B 130
 8 int pixel[A][B][C];
 9 bool pixelif[A][B][C]={
10     false
11 };
12 struct Node
13 {
14     int x,y,z;
15 }node;
16 int M,N,L,T;
17 int X[6]={
18     0,0,0,0,1,-1
19 };
20 int Y[6]={
21     0,0,1,-1,0,0
22 };
23 int Z[6]={
24     1,-1,0,0,0,0
25 };
26 bool Judge(int x,int y,int z)
27 {
28     if(x<0||x>=M||y<0||y>=N||z<0||z>=L)
29       return false;
30     if(pixel[x][y][z]==0||pixelif[x][y][z]==true)
31       return false;
32     return true;
33 }
34 int BFS(int z,int x,int y)
35 {
36     int total=0;
37     queue<Node> Q;
38     node.z=z;
39     node.x=x;
40     node.y=y;
41     Q.push(node);
42     pixelif[x][y][z]=true;
43     while(!Q.empty())
44     {
45         Node top=Q.front();//没有front。。。 
46         Q.pop();
47         total++;
48         for(int i=0;i<6;i++)
49         {
50             int newX=top.x+X[i];
51             int newY=top.y+Y[i];
52             int newZ=top.z+Z[i];
53             if(Judge(newX,newY,newZ))
54             {
55                 node.x=newX;
56                 node.y=newY;
57                 node.z=newZ;
58                 Q.push(node);
59                 pixelif[newX][newY][newZ]=true;
60             }
61         }
62     }
63     if(total<T)
64       return 0;
65     else
66       return total;
67 }
68 int main(int argc, char *argv[])
69 {
70     scanf("%d%d%d%d",&M,&N,&L,&T);
71     for(int i=0;i<L;i++)
72     {
73         for(int j=0;j<M;j++)
74         {
75             for(int k=0;k<N;k++)
76             {
77                 scanf("%d",&pixel[j][k][i]);
78             }
79         }
80     }
81     int ans=0;
82     for(int z=0;z<L;z++)
83     {
84         for(int x=0;x<M;x++)
85         {
86             for(int y=0;y<N;y++)
87             {
88                 if(pixelif[x][y][z]==false&&pixel[x][y][z]==1)
89                 {
90                     ans+=BFS(z,x,y);
91                 }
92             }
93         }
94     }
95     printf("%d\n",ans);
96     return 0;
97 }
View Code

 

PAT1091Acute Stroke

标签:

原文地址:http://www.cnblogs.com/GoFly/p/4299307.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!