1091. Acute Stroke
2016-10-05 18:28
148 查看
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.
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
刚开始读题莫名地想到了图像处理里的腐蚀操作,可是并没有单元。第一次遇到3维的连通性的问题,连数组可以3维定义和表示都以为不存在。。。
把 Uncle_Sugar 的文章看了,很清晰,学到了。
对于方向的处理,第一次见到这样的操作,确实很方便,另外,在对于结构体,呃,叫初始化么,即定义的时候直接赋值操作我见过但是没用过,以后要用一下,这里是很方便的。
贴别人的代码哈哈:
# include <cstdio> # include <queue> using std::queue; int map[1286][128][60]; struct loca { int x,y,z; loca(int _x,int _y,int _z):x(_x),y(_y),z(_z){} }; int m,n,l,t; int dx[6] = {1,-1,0,0,0,0}; int dy[6] = {0,0,1,-1,0,0}; int dz[6] = {0,0,0,0,1,-1}; int ans = 0; int InRange(int x,int y,int z) { return x<m&&x>=0&&y<n&&y>=0&&z<l&&z>=0; } void bfs(int x,int y,int z) { int ret = 0; queue<loca> que; que.push(loca(x,y,z)); map[x][y][z] = 0;ret++; while (!que.empty()) { loca tp = que.front();que.pop(); x = tp.x; y = tp.y; z = tp.z; for (int i=0;i<6;i++) { int nx = x + dx[i]; int ny = y + dy[i]; int nz = z + dz[i]; if (InRange(nx,ny,nz)&&map[nx][ny][nz] == 1) { map[nx][ny][nz] = 0;ret++; a572 que.push(loca(nx,ny,nz)); } } } if (ret>=t) ans += ret; } int main() { scanf("%d%d%d%d",&m,&n,&l,&t); for (int k=0;k<l;k++) for (int i=0;i<m;i++) for (int j=0;j<n;j++) scanf("%d",&map[i][j][k]); for (int k=0;k<l;k++) for (int i=0;i<m;i++) for (int j=0;j<n;j++) if (map[i][j][k]==1) bfs(i,j,k); printf("%d\n",ans); return 0; }
相关文章推荐
- PAT - 甲级 - 1091. Acute Stroke (30)(三维BFS)
- 1091. Acute Stroke (30)
- 1091. Acute Stroke (30)
- 1091. Acute Stroke (30)
- 1091. Acute Stroke(30)
- 1091. Acute Stroke (30)//BFS!!!
- PAT 1091. Acute Stroke (30)
- 1091. Acute Stroke (30)
- 1091. Acute Stroke 解析
- Pat(Advanced Level)Practice--1091(Acute Stroke)
- 1091. Acute Stroke (30) -- DFS(三维空间)
- PAT-A | 1091 | Acute Stroke
- 1091. Acute Stroke (30)
- PAT (Advanced Level) Practise 1091 Acute Stroke (30)
- PAT1091. Acute Stroke (30)
- 1091. Acute Stroke (30)
- 1091. Acute Stroke (30)
- PAT 1091. Acute Stroke (30) 3重方向并查集(其实非递归DFS也可以,,)
- 1091. Acute Stroke (30)
- 1091. Acute Stroke (30)