【PAT】1091 Acute Stroke(30 分)
1091 Acute Stroke(30 分)
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×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×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
C++代码如下:
#include<iostream>
#include<queue> using namespace std; int num[][][];
int inq[][][]; int X[] = { ,,,,,- };
int Y[] = { ,,,-,, };
int Z[] = { ,-,,,, }; int m, n, k, t;
int ans=;
struct Node
{
int x, y, z;
}node; bool judge(int x, int y, int z) {
if (x >= m || x < || y < || z < || y >= n || z >= k) return false;
if (num[x][y][z] == || inq[x][y][z] == true) return false;
return true;
} void BFS(int x, int y, int z) {
node.x = x, node.y = y, node.z = z;
queue<Node>q;
q.push(node);
inq[x][y][z] = true;
int count = ;
while (!q.empty()) {
Node top = q.front();
q.pop();
count++;
for (int i = ; i < ; i++) {
int newx = top.x + X[i];
int newy = top.y + Y[i];
int newz = top.z + Z[i];
if (judge(newx, newy, newz)) {
node.x = newx, node.y = newy, node.z = newz;
q.push(node);
inq[newx][newy][newz] = true;
}
}
}
if (count >= t) ans += count;
} int main() {
cin >> m >> n >> k >> t;
int temp;
for(int z=;z<k;z++)
for (int x = ; x < m; x++)
for (int y = ; y < n; y++) {
cin >> temp;
num[x][y][z] = temp;
}
for(int z=;z<k;z++)
for(int x=;x<m;x++)
for (int y = ; y < n; y++) {
if (num[x][y][z] == && inq[x][y][z] == false) {
BFS(x, y, z);
}
}
cout << ans << endl;
return ;
}
【PAT】1091 Acute Stroke(30 分)的更多相关文章
- 【PAT甲级】1091 Acute Stroke (30 分)(BFS)
题意: 输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小.输出一共有多少个单元满足所在联通块大小大于等于T. tr ...
- PAT 1091 Acute Stroke [难][bfs]
1091 Acute Stroke (30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the ...
- 1091 Acute Stroke (30)(30 分)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 1091. Acute Stroke (30)
题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...
- PAT 1091. Acute Stroke (bfs)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- PAT (Advanced Level) 1091. Acute Stroke (30)
BFS求连通块.递归会爆栈. #include<cstdio> #include<cstring> #include<cmath> #include<algo ...
- PAT甲题题解-1091. Acute Stroke (30)-BFS
题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...
- pat1091. Acute Stroke (30)
1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...
- [PAT] 1147 Heaps(30 分)
1147 Heaps(30 分) In computer science, a heap is a specialized tree-based data structure that satisfi ...
随机推荐
- BZOJ5461 PKUWC2018Minimax(概率期望+线段树合并+动态规划)
离散化后,容易想到设f[i][j]为i节点权值为j的概率,不妨设j权值在左子树,则有f[i][j]=f[lson][j](pi·f[rson][1~j]+(1-pi)·f[rson][j~m]). 考 ...
- VS2010 代码突然改变字体 解决办法
sfsfsddffs dffsfsfsfsf 如上,第一行是突然变成宽体的字体,第二行是恢复后的字体,方法就是: shift+空格键,一起按就会在这两种字体之间变换~
- HDU 5574 Colorful Tree
• 给出一棵树,每个点有初始的颜色,支持两种操作• 将一个点的子树染成一种给定颜色• 问一个点的子树里有几种不同的颜色 •
- Python之文件与目录操作(os、zipfile、tarfile、shutil)
Python中可以用于对文件和目录进行操作的内置模块包括: 模块/函数名称 功能描述 open()函数 文件读取或写入 os.path模块 文件路径操作 os模块 文件和目录简单操作 zipfile模 ...
- mybatis的面试一对一,一对多,多对多的mapper.xml配置
使用springboot完成一对一,一对多: https://blog.csdn.net/KingBoyWorld/article/details/78966789 传统的mapper文件中的一对一, ...
- python的内置模块之os模块方法详解以及使用
1.getcwd() 获取当前工作路径 import os print(os.getcwd()) C:\python35\python3.exe D:/pyproject/day21模块/os模块.p ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
- bzoj千题计划270:bzoj4559: [JLoi2016]成绩比较(拉格朗日插值)
http://www.lydsy.com/JudgeOnline/problem.php?id=4559 f[i][j] 表示前i门课,有j个人没有被碾压的方案数 g[i] 表示第i门课,满足B神排名 ...
- hdu 5956 The Elder
http://acm.hdu.edu.cn/showproblem.php?pid=5956 转移方程:dp[i]=(dis[i]-dis[j])*(dis[i]-dis[j])+P+dp[j] 斜率 ...
- 20155218 2006-2007-2 《Java程序设计》第5周学习总结
20155218 2006-2007-2 <Java程序设计>第5周学习总结 教材学习内容总结 java中的错误都会被包装成对象,且是可抛出的. 通常称错误处理为异常处理,程序设计本身的错 ...