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 0Sample 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;}
- 【PAT】A1091. Acute Stroke (30)
- PAT A1091. Acute Stroke (30)
- pat-a1091. Acute Stroke (30)
- A1091. Acute Stroke (30)
- PAT Acute Stroke (30)
- pat- Acute Stroke (30)
- PAT 1091. Acute Stroke (30)
- PAT 1091. Acute Stroke (30)
- 【PAT】1091. Acute Stroke (30)
- PAT 1091. Acute Stroke (30)
- PAT A 1091. Acute Stroke (30)
- PAT(Advance) 1091. Acute Stroke (30)
- PAT 1091. Acute Stroke (30)(孤岛问题)
- PAT(A) - 1091. Acute Stroke (30)
- PAT--1091. Acute Stroke (30)(三维bfs)
- 1091. Acute Stroke (30) PAT甲级
- PAT-A-1091. Acute Stroke (30)
- Pat(A) 1091. Acute Stroke (30)
- Spring mvc和SSH如何取舍?
- 有关cocoaPods的一些坑
- PAT 乙级 1031. 查验身份证(15) Java版
- Altium Designer PCB导线高亮
- 在WebView中添加定位功能
- PAT A1091. Acute Stroke (30)
- E
- Windows下 solr6.4.1新建core
- genymotion的一种快速下载镜像的方法
- ReactNative中把js编译成bundle后,js引用的图片的去向
- 如何测试一个网页登陆界面
- extern “C”的用法
- java.sql.SQLException: Access denied for user 'ROOT'@'localhost' (using password: YES)
- 数据结构之顺序表实现