PAT A1091. Acute Stroke (30)

来源:互联网 发布:sql语句大全实例 编辑:程序博客网 时间:2024/04/29 07:26

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 21 1 1 11 1 1 11 1 1 10 0 1 10 0 1 10 0 1 11 0 1 10 1 0 00 0 0 01 0 1 10 0 0 00 0 0 00 0 0 10 0 0 11 0 0 0
Sample Output:
26
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <queue>#include <vector>using namespace std;int slice[1287][129][61];bool visit[1287][129][61]={false};int m,n,l,t;struct Slice{int x,y,z;}S;bool indefy(int x ,int y,int z){if(x<0||y<0||z<0) return false;if(x>=m||y>=n||z>=l) return false ;if(visit[x][y][z]==true||slice[x][y][z]==0) return false ;return true;}int Z[6]={1,-1,0,0,0,0};int Y[6]={0,0,1,-1,0,0};int X[6]={0,0,0,0,1,-1};int BFS(int x,int y,int z){int man=0;queue<Slice> Q;S.x=x;S.y=y;S.z=z;Q.push(S);visit[x][y][z]=true;while(!Q.empty()){Slice nn=Q.front();Q.pop();man++;for(int i=0;i<6;i++){int nx=nn.x+X[i];int ny=nn.y+Y[i];int nz=nn.z+Z[i];if(indefy(nx,ny,nz)){S.x=nx;S.y=ny;S.z=nz;Q.push(S);visit[S.x][S.y][S.z]=true;}}if(man>=t)  return man;else return 0; }}int main(){int num=0;scanf("%d%d%d%d",&m,&n,&l,&t);for(int z=0;z<l;z++){for(int i=0;i<m;i++){for(int j=0;j<n;j++){scanf("%d",&slice[i][j][z]);visit[i][j][z]==false;}}}for(int z=0;z<l;z++){for(int i=0;i<m;i++){for(int j=0;j<n;j++){if(visit[i][j][z] == false&&slice[i][j][z]==1){num+=BFS(i,j,z);}}}}printf("%d\n",num);system("pause");return 0;}

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 要去当兵有痔疮怎么办 狗舔的东西吃了怎么办 婚检说生过孩子怎么办 劳动法规定身体有疾病的怎么办 铁路对职工醉驾怎么办 入职体检高血糖怎么办 睾丸捏一下很疼怎么办 小孩睾丸受外力红肿该怎么办 睾丸炎症怎么办啊会不会不育呢 腰疼连着睾丸疼怎么办 为什么结石会睾丸疼怎么办 感觉自己睾丸变小了怎么办 宝宝小丁丁肿了怎么办 两岁宝宝高低肩怎么办 参军体检视力不过关怎么办 验兵视力不过关怎么办 军检了感冒了怎么办 双侧附睾头囊肿怎么办 睾丸上面长疙瘩很痒都抓烂了怎么办 睾丸小引起精子数量少怎么办 睾丸发育不完全精子存活率低怎么办 踢到睾丸很痛怎么办 兔子的睾丸烂了怎么办 梗阻性无精穿刺取得精子不好怎么办 甲状腺做完穿刺后是恶性怎么办 硬了之后睾丸痛怎么办 腋下胯间颜色深怎么办 当兵前上班有社保怎么办 别人背后害我我怎么办 左侧胸明显大于右侧胸怎么办 婴儿拉大便次数多怎么办 公鸽子不会踩蛋怎么办 生殖器套东西取不下来怎么办 婴儿成蛋蛋的皮好长怎么办 丈夫总要害自己该怎么办 脚背踢肿了怎么办很疼 踢沙袋脚背伤了怎么办 脚y子烂了怎么办 掐喉咙那会痒会咳嗽怎么办 掐到婴儿脖子了怎么办 孩子胳膊不小心烫破皮了怎么办