PAT 1091. Acute Stroke (30)
2015-09-09 15:34
393 查看
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
这道题就相当于给了一个图,求图中点数大于阈值的连通图的点数总和。只不过这个图是三维的。和二维的做法一样,用BFS或DFS即可,只是这道题我用DFS的时候出现了段错误,所以最后还是选择用了BFS。代码如下:
#include <iostream> #include <vector> #include <queue> #include <cstring> using namespace std; int brain[1286][128][60]; typedef struct node{ int x,y,z; node(int ps,int py,int pz):x(ps),y(py),z(pz){} }node; int N,M,L,T; int bfs(int x,int y,int z) { int count=0; queue<node> myqueue; myqueue.push(node(x,y,z)); while(myqueue.size()) { node temp=myqueue.front(); myqueue.pop(); if(brain[temp.x][temp.y][temp.z]) count++; else continue; brain[temp.x][temp.y][temp.z]=0; if(temp.x-1>=0) myqueue.push(node(temp.x-1,temp.y,temp.z)); if(temp.x+1<N) myqueue.push(node(temp.x+1,temp.y,temp.z)); if(temp.y-1>=0) myqueue.push(node(temp.x,temp.y-1,temp.z)); if(temp.y+1<M) myqueue.push(node(temp.x,temp.y+1,temp.z)); if(temp.z-1>=0) myqueue.push(node(temp.x,temp.y,temp.z-1)); if(temp.z+1<L) myqueue.push(node(temp.x,temp.y,temp.z+1)); } return count; } int main(void) { memset(brain,0,sizeof(brain)); cin>>M>>N>>L>>T; for(int i=0;i<L;i++) for(int j=0;j<M;j++) for(int k=0;k<N;k++) scanf("%d",&brain[k][j][i]); int count=0; for(int i=0;i<L;i++) for(int j=0;j<M;j++) for(int k=0;k<N;k++) { int max=bfs(k,j,i); if(max>=T) count+=max; } cout<<count; return 0; }
相关文章推荐
- 学习VIM——网络资源
- java深入学习(一)
- Java正则表达式应用
- 64位win7启动VirtualBox出错Error e_fail 0x80004005
- tmux使用笔记
- 杭电ACM2056java做法
- [持续更新]CSS3学习笔记(三)弹性盒子
- 把数组排成最小的数
- 唠叨唠叨最近
- Java:多线程,线程池,使用CompletionService通过Future来处理Callable的返回结果
- js页面加载顺序
- 数学思想方法-sasMEMO(17)
- 唠叨唠叨最近
- 西电 Linux系统 Ubuntu 15.04 64位 连接校园网
- 使用epeg生成无压缩的缩略图
- 肾果手机App Store切换区域(无需Visa或者万事达)
- ios开发文字排版,段落排版,富文本
- ecshop不同城市显示不同商品之后台添加屏蔽城市
- Android工程目录结构详解
- php的mysql_connect连接遇到的2006问题