Source:

PAT A1091 Acute Stroke (30 分)

Description:

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, Land T, where M and N are the sizes of each slice (i.e. pixels of a slice are in an M×N matrix, and the maximum resolution is 1286 by 128); L (≤) 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×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

Keys:

  • 广度优先搜索(Breadth First Search)

Attention:

  • 4,5测试点用递归会爆栈(段错误)

Code:

 /*
time: 2019-08-26 17:10:21
problem: PAT_A1091#Acute Stroke
AC: 36:38 题目大意:
给出脑部各层的切片,患病几率与连续病变区域的数量有关,计算患病区域数量
输入:
第一行给出,各层的长度M<=1286和宽度N<=128,层数L<=60,患病阈值T(连续病变区域>=T时患病)
接下来L行,给出各层的信息,1病变,0正常
输出:
打印患病的病变区域数量 基本思路:
BFS统计各个块的有效结点数
*/
#include<cstdio>
#include<queue>
using namespace std;
const int L=,M=,N=;
struct node
{
int x,y,z;
};
int l,m,n,t,cnt,sum=,grap[L][M][N],vis[L][M][N];
int X[]={,-,,,,},Y[]={,,,-,,},Z[]={,,,,,-}; void BFS(int z,int x, int y)
{
grap[z][x][y]=;
queue<node> q;
q.push(node{x,y,z});
while(!q.empty())
{
node r = q.front();
q.pop();cnt++;
for(int i=; i<; i++)
{
int u=r.x+X[i],v=r.y+Y[i],w=r.z+Z[i];
if(u>=&&u<m&&v>=&&v<n&&w>=&&w<l)
if(grap[w][u][v]==)
{
grap[w][u][v]=;
q.push(node{u,v,w});
}
}
}
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE scanf("%d%d%d%d", &m,&n,&l,&t);
for(int k=; k<l; k++)
for(int i=; i<m; i++)
for(int j=; j<n; j++)
scanf("%d", &grap[k][i][j]);
for(int k=; k<l; k++)
for(int i=; i<m; i++)
for(int j=; j<n; j++)
if(grap[k][i][j]==)
{
cnt=;
BFS(k,i,j);
if(cnt>=t)
sum+=cnt;
}
printf("%d", sum); return ;
}

最新文章

  1. MSSQL 基础语句笔记
  2. Java:Remote Debug
  3. java基础之 序列化
  4. PHP ServerPush (推送) 技术的探讨
  5. linux常见目录的作用
  6. alt属性
  7. spring核心组件
  8. passport 自动取密码
  9. 解决前端浏览器传JSON对像到服务端后全部变成string类型的方法
  10. Python 学习笔记3
  11. 使用jquery.qrcode.js生成二维码
  12. 群晖IP地址更新问题
  13. IPv6实验1_IPv6地址配置
  14. Netty 之 Netty生产级的心跳和重连机制
  15. 高度自适应的div
  16. 源码分析八( hashmap工作原理)
  17. git协同开发
  18. PAT 乙级 1067 试密码(20 分)
  19. HI-LO计数法,赌桌,与机会
  20. C语言/C++编程学习:栈的代码实现之数组方案

热门文章

  1. Appium+python自动化-查看app元素属性
  2. python自动化之函数封装
  3. 使用函数指针模拟C++多态
  4. java并发编程笔记(四)——安全发布对象
  5. mongo大数据量更新服务端超时解决: Cursor not found, cursor id: 82792803897
  6. Win10+CentOS7双系统引导修复
  7. 如何深入理解Java泛型
  8. Error(10028):Can&#39;t resolve multiple constant drivers for net “ ” at **.v
  9. 线程分离pthread_detach()中的return()和pthread_exit()
  10. Inversion of Control 控制反转 有什么好处