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 分)的更多相关文章

  1. 【PAT甲级】1091 Acute Stroke (30 分)(BFS)

    题意: 输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小.输出一共有多少个单元满足所在联通块大小大于等于T. tr ...

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

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

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

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

  4. 1091. Acute Stroke (30)

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

  5. PAT 1091. Acute Stroke (bfs)

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

  6. PAT (Advanced Level) 1091. Acute Stroke (30)

    BFS求连通块.递归会爆栈. #include<cstdio> #include<cstring> #include<cmath> #include<algo ...

  7. PAT甲题题解-1091. Acute Stroke (30)-BFS

    题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...

  8. pat1091. Acute Stroke (30)

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

  9. [PAT] 1147 Heaps(30 分)

    1147 Heaps(30 分) In computer science, a heap is a specialized tree-based data structure that satisfi ...

随机推荐

  1. Java移动文件到另外一个目录

    private void moveTotherFolders(String pathName,String fileName,String ansPath){ String startPath = t ...

  2. ssh框架配置过程

    1.pom.xml配置依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&qu ...

  3. eos 源码net_plugin分析

    1 net_plugin_impl::connect(connection_ptr c) 函数用于解析地址,内部异步回调async_resolve async_resolve 传递了lambda表达式 ...

  4. 鸟哥的Linux私房菜——第十三章:Vim编译器

    视频链接: 土豆: B站:http://www.bilibili.com/video/av9891085/ 本章的细节还是挺多的,可是我懒啊~~

  5. Maven的国内镜像(解决jar下载过慢)

    Maven简介 maven作为一个项目管理工具确实非常好用,结果在使用时候,你会发现下载jar速度不如自己在网上下载.之前oschina的中央仓库可用,现在oschina的maven服务器关了,只能拿 ...

  6. JeeSite 4.x 树形结构的表设计和用法

    有些同仁对于 JeeSite 4 中的树表设计不太了解,本应简单的方法就可实现,却写了很多复杂的语句和代码,所以有了这篇文章. 在 JeeSite 4 中的树表设计我还是相对满意的,这种设计比较容易理 ...

  7. 数学:二次剩余与n次剩余

    二次剩余求的是这个东西 如果给定x,再给定若干个大的质数p,如果结果a相同,那么x是完全平方数? 给出别人的二次剩余的代码: /*poj 1808 题意: 判断平方剩余,即判断(x^2)%p=a是否有 ...

  8. Zookeeper集群 + Kafka集群 + KafkaOffsetMonitor 监控

    一.Zookeeper ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一 ...

  9. Python人工智能之路 - 第一篇 : 你得会点儿Python基础

    Python 号称是最接近人工智能的语言,因为它的动态便捷性和灵活的三方扩展,成就了它在人工智能领域的丰碑 走进Python,靠近人工智能 一.编程语言Python的基础 之 "浅入浅出&q ...

  10. insert into与insert ignore以及replace into的区别

    insert ignore表示,如果表中已经存在相同的记录,则忽略当前新数据: INSERT INTO有无数据都插入,如果主键则不插入; REPLACE INTO 如果是主键插入则会替换以前的数据; ...