A1091. Acute Stroke (30)

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 <stdio.h>
 2 #include <stdlib.h>
 3 #include <iostream>
 4 #include <string.h>
 5 #include <math.h>
 6 #include <algorithm>
 7 #include <string>
 8 #include <stack>
 9 #include <queue>
10 using namespace std;
11 struct node{
12   int x,y,z;
13 }Node;
14 int n,m,slice,T;
15 int pixel[1290][130][61];
16 int inq[1290][130][61]={false};
17 int X[6]={0,0,0,0,1,-1};
18 int Y[6]={0,0,1,-1,0,0};
19 int Z[6]={1,-1,0,0,0,0};
20 bool judge(int x,int y,int z)//判断是否有访问的必要 ,inq表示是否入队列,如果可以访问,就入队
21 {
22     if(x>=m||x<0||y>=n||y<0||z>=slice||z<0)return false;
23     if(pixel[x][y][z]==0||inq[x][y][z]==true)return false;
24     return true;
25 }
26
27 int BFS(int x,int y,int z)//进行宽度优先搜索,目的是搜索出相连的一块1
28 {
29     int total=0;//当前块数为0;
30     queue<node> Q;//定义当前队列;
31     Node.x=x;Node.y=y;Node.z=z;
32     Q.push(Node);
33     inq[x][y][z]=true;
34     while(!Q.empty())
35     {
36         node top=Q.front();
37         Q.pop();
38         total++;
39         for(int i=0;i<6;i++)
40         {
41             int newx=top.x+X[i];
42             int newy=top.y+Y[i];
43             int newz=top.z+Z[i];
44             if(judge(newx,newy,newz)==true)
45             {
46                 Node.x=newx;
47                 Node.y=newy;
48                 Node.z=newz;
49                 Q.push(Node);
50                 inq[newx][newy][newz]=true;
51             }
52         }
53
54     }
55     if(total>=T) return total;
56     else return 0;
57
58 }
59 int main(){
60     scanf("%d %d %d %d",&m,&n,&slice,&T);
61       for(int z=0;z<slice;z++)
62     {
63         for(int x=0;x<m;x++)
64         {
65             for(int y=0;y<n;y++)
66             {
67                    scanf("%d",&pixel[x][y][z]);
68             }
69
70         }
71     }
72     int ans=0;
73     for(int z=0;z<slice;z++)
74     {
75         for(int x=0;x<m;x++)
76         {
77             for(int y=0;y<n;y++)
78             {
79                if(pixel[x][y][z]==1&&inq[x][y][z]==false)
80                {
81                    ans+=BFS(x,y,z);
82                }
83             }
84
85         }
86     }
87     printf("%d\n",ans);
88     return 0;
89 }
时间: 2024-08-08 13:10:19

A1091. Acute Stroke (30)的相关文章

搜索专题 BFS A1091.Acute Stroke(30)

#pragma warning(disable:4996) #include <stdio.h> #include <stdlib.h> #include <queue> using namespace std; struct node{ int x, y, z; }p; int m, n, l, t, volume = 0; int brain[1300][130][61], bbrain[1300][130][61]; //右,左,上,下,前,后 int X[] =

A1091 Acute Stroke (30分)

一.技术总结 这一题是BFS广度优先搜索算法,感觉这类题目是首先定义需要的数据结构类型,然后会定义一个数组用于存放数据,还有一个bool类型的数组看是否已经放入队列中了.然后再编写一个判断函数judge()排除数组中超出范围的数字返回false,还有就是不满足条件或者是已经在队列中的,最后就返回true. 同时也应该定义一个广度扩散的二维或三维数组. 编写BFS函数,首先定义需要的变量,然后定义一个队列终于记录,把传入的参数赋给数据结构,然后push进入队列中,然后再编写while循环,只要队列

PAT Acute Stroke (30)

题目描述 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. 输入描述:

pat1091. Acute Stroke (30)

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 iden

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

题目信息 1091. Acute Stroke (30) 时间限制400 ms 内存限制65536 kB 代码长度限制16000 B 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,

PAT 1091. Acute Stroke (30)

1091. Acute Stroke (30) 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

【PAT甲级】1091 Acute Stroke (30分)

1091 Acute Stroke (30分) 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

1091. Acute Stroke (30)

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 Spec

PAT甲题题解-1091. Acute Stroke (30)-BFS

题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写,想有没有别的办法.然而结果是,实在想不出别的办法了,所以还是尝试写写dfs.bfs. 一开始先用了dfs,最后两个样例段错误,估计是栈溢出了.之所以dfs栈溢出,因为dfs的时候每个状态都会存储在堆栈里,就好比dfs的第一个状态,一直保存到最后整个dfs结束.而bfs是存储在队列中,每次队列都会有状态取