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 ;
}

PAT_A1091#Acute Stroke的更多相关文章

  1. 1091. Acute Stroke (30)

    题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...

  2. PAT1091:Acute Stroke

    1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...

  3. A1091. Acute Stroke

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  4. 【PAT】1091 Acute Stroke(30 分)

    1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...

  5. PAT 1091 Acute Stroke [难][bfs]

    1091 Acute Stroke (30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the ...

  6. pat1091. Acute Stroke (30)

    1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...

  7. 1091 Acute Stroke (30)(30 分)

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  8. PAT 1091. Acute Stroke (bfs)

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  9. PAT甲级——A1091 Acute Stroke【30】

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

随机推荐

  1. JAVA学习之面向对象

    面向对象是相对面向过程而言面向过程:强调的是功能行为面向对象:将功能封装进对象,强调具备了功能的对象 不论面向对象还是面向过程都是一种开发思想而已.举一个例子来理解面向对象和面向过程把大象装进冰箱分三 ...

  2. Dubbo入门到精通学习笔记(二十):MyCat在MySQL主从复制的基础上实现读写分离、MyCat 集群部署(HAProxy + MyCat)、MyCat 高可用负载均衡集群Keepalived

    文章目录 MyCat在MySQL主从复制的基础上实现读写分离 一.环境 二.依赖课程 三.MyCat 介绍 ( MyCat 官网:http://mycat.org.cn/ ) 四.MyCat 的安装 ...

  3. python学习笔记:操作Excle

    import xlwt #写excel import xlrd #读excel import xlutils #修改excel 一.写操作 1.写Excel import xlwt #写excel,导 ...

  4. jQuery选择器我犯的错误(原创)

    jQuery的选择器十分强大,但是在使用jQuery选择器的时候一定要十分小心,空格.冒号.引号到处都是坑,老手也不能避免,只能勤加练习,熟能生巧,掌握规律,为了练习,凡是到选择器的地方我都自己先敲, ...

  5. freemarker在web应用项目的使用

    FreeMarker是一个用Java语言编写的模板引擎,它基于模板来生成文本输出.FreeMarker与Web容器无关,即在Web运行时,它并不知道Servlet或HTTP.它不仅可以用作表现层的实现 ...

  6. SSD网络结构

    SSD算法,其英文全名是Single Shot MultiBox Detector. SSD的网络结构流程如下图所示:SSD总共11个block,相比较于之前的VGG16,改变了第5个block的第4 ...

  7. JavaScript性能优化之摇树

    作者|Jeremy Wagner译者|薛命灯 现代 Web 应用程序可能会变得非常巨大,特别是它们的 JavaScript 部分.HTTP Archive 网站的数据显示,截至 2018 年中,传输到 ...

  8. 非关系型数据库MongoDB入门

    本文分为以下四块简单介绍非关系型数据库MongoDB:1.MongoDB简介.2.MongoDB和关系数据库对比.3.MongoDB基本概念.4.mongo shell的使用以及对MongoDB的增删 ...

  9. Vue中的作用域插槽

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. python 对列表中任意两个数进行操作 (python operate any two elements in list)

    python中, 实现列表中的整型元素两两相乘或列表中的数组元素两两相与 1. 假设列表中的元素是整型, 可调用以下函数: def list_any_two_mul(mylist):      num ...