PAT(甲级)1091
2015-09-29 11:08
411 查看
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
#include <cstdio> #include <iostream> #include <cstring> #include <stack> using namespace std; const int MSIZE = 1290; const int NSIZE = 130; const int LSIZE = 61; bool slices[LSIZE][MSIZE][NSIZE]; int M,N,L,T; int count = 0; bool find_next(int &ks,int &is,int &js){ if(ks >= L|| is>= M||js >=N || ks < 0 || is <0 ||js <0) return false; for(js;js<N;js++) if(slices[ks][is][js]) return true; for(is++;is<M;is++){ for(js=0;js<N;js++) if(slices[ks][is][js]){ return true ; } } for(ks++;ks<L;ks++) for(is = 0;is<M;is++) for(js = 0;js<N;js++) if(slices[ks][is][js]) return true ; return false; } struct Number{ Number(int k1,int i1,int j1):k(k1),i(i1),j(j1){ } int k; int i; int j; }; stack<Number > s; void travel(int k,int i,int j){ slices[k][i][j] = false; s.push(Number(k,i,j)); count++; while(!s.empty()){ Number cur = s.top(); s.pop(); int k = cur.k; int i = cur.i; int j = cur.j; if(j+1 <N && slices[k][i][j+1]){ count++; slices[k][i][j+1] = false; s.push(Number(k,i,j+1)); } if(j-1 >=0 && slices[k][i][j-1]){ count++; slices[k][i][j-1] = false; s.push(Number(k,i,j-1)); } if(i+1 <M && slices[k][i+1][j]){ count++; slices[k][i+1][j] = false; s.push(Number(k,i+1,j)); } if(i-1 >=0 && slices[k][i-1][j]){ count++; slices[k][i-1][j] = false; s.push(Number(k,i-1,j)); } if(k+1 <L && slices[k+1][i][j]){ count++; slices[k+1][i][j] = false; s.push(Number(k+1,i,j)); } if(k-1 >= 0 && slices[k-1][i][j]){ count++; slices[k-1][i][j] = false; s.push(Number(k-1,i,j)); } } } /* this function can cause segment falt void travel(int k,int i,int j){ if(k >= L || k <0 || i <0 || i >= M|| j <0 || j >= N ) // if(k >= L || i >=M || j >=N) return ; if(!slices[k][i][j]) return ; else{ count++; slices[k][i][j] = false; travel(k,i,j+1); travel(k,i+1,j); travel(k+1,i,j); travel(k,i,j-1); travel(k,i-1,j); travel(k-1,i,j); } }*/ int main() { // freopen("test.txt","r",stdin); 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",&slices[k][i][j]); } int kstart=0,istart=0,jstart=0; int total_count=0; while(find_next(kstart,istart,jstart)){ travel(kstart,istart,jstart); if(count >= T) total_count += count; count = 0; } printf("%d\n",total_count); return 0; }
相关文章推荐
- DNS服务之正反向解析、主从服务配置
- 你没有变强,只因你不够努力
- 模块
- 协程实现的基础与方式
- Unity-EasyTouch插件之ReservedArea的运用(主要是避免JoyStick与Touch的矛盾)
- Android应用程序如何调用支付宝接口
- c/c++生成不重复的字符串(6个字符组成,可表示的个数可以扩充),简易版数据库主键
- Unity-EasyTouch插件之ReservedArea的运用(主要是避免JoyStick与Touch的矛盾)
- Android 使用高德SDK实现导航笔记
- mysql 索引设计准则
- PCM与DSD究竟是什么??
- jQuery.validate验证上传文件大小
- PAT(甲级)1090
- 在Ubuntu中安装Redis
- Retrofit 1.9源码学习
- 《modern operating system》 chapter 5 Input and output 注意事项
- 城市天气三小时预报,天气预报接口实现
- 企业中如何给数据库用户授权
- apache搭建完成测试PHP页面
- tomcat性能调优