PAT_A1091#Acute Stroke
Source:
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的更多相关文章
- 1091. Acute Stroke (30)
题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...
- PAT1091:Acute Stroke
1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...
- A1091. Acute Stroke
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 【PAT】1091 Acute Stroke(30 分)
1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...
- PAT 1091 Acute Stroke [难][bfs]
1091 Acute Stroke (30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the ...
- pat1091. Acute Stroke (30)
1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...
- 1091 Acute Stroke (30)(30 分)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- PAT 1091. Acute Stroke (bfs)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- PAT甲级——A1091 Acute Stroke【30】
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
随机推荐
- 前端学习笔记——引入css文件、样式优先级
CSS样式的引用方式有三种:行间样式表>内部样式表>外部样式表. 如果只有一种样式,那么优先级“由内到外 由近到远” 1.行间样式表--内联方式 内联方式指的是直接在 HTML 标签中的 ...
- raid 10
首先先创建五个新的硬盘,步骤参照 raid 5 建好硬盘以后开启虚拟机 打开终端,更改好主机名以后,重新打开终端 输入命令:fdisk -l 查看有没有加入进来 我们发现已经加入进来 然后开始分 ...
- mybatis自学历程(二)
传递多个参数 1.在mybatis.xml下<mappers>下使用<package> <mappers> <package name="com.m ...
- Codesforces 485D Maximum Value
D. Maximum Value You are given a sequence a cons ...
- UVALive 4794 Sharing Chocolate
Sharing Chocolate Chocolate in its many forms is enjoyed by millions of people around the world ever ...
- USACO 2014 US Open Decorating The Pastures
题目大意: 给定n个点m条边的无向图 判断这个图能否将所有点依次染色为F J F J 若能输出最多能染多少个J 若不能输出-1 就是给一个图01染色 过程中判断是否出现不符合的情况 即点1到点2到点3 ...
- Cas 4.2.7 OAuth+Rest 实现SSO
关于Cas的认证原理.Rest的使用请参考前面的文章.本文重点阐述使用Rest接口登陆系统和其他单点登录系统打通遇到的问题,及解决问题的思路和过程. 一: 遇到的问题 使用Res ...
- MySql进行批量插入时的几种sql写法
insert into:插入数据,如果主键重复,则报错 insert repalce:插入替换数据,如果存在主键或unique数据则替换数据 insert ignore:如果存在数据,则忽略. INS ...
- pair queue____多源图广搜
.简介 class pair ,中文译为对组,可以将两个值视为一个单元.对于map和multimap,就是用pairs来管理value/key的成对元素.任何函数需要回传两个值,也需要pair. 该函 ...
- 解决mybatisplus saveBatch 或者save 无法插入主键问题
解决mybatisplus saveBatch 或者save 无法插入主键问题 通过跟踪源码后得出结论,由于插入的表的主键不是自增的,而是手动赋值的,所以在调用saveBatch 执行的sql语句是没 ...