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. 点分治&动态点分治小结

    (写篇博客证明自己还活着×2) 转载请注明原文地址:http://www.cnblogs.com/LadyLex/p/8006488.html 有的时候,我们会发现这样一类题:它长得很像一个$O(n) ...

  2. JS发送跨域Post请求出现两次请求的解决办法

    原文地址: http://www.cnblogs.com/JimmyBright/p/7681097.html 所有跨域的js在提交post请求的时候,如果服务端设置了可跨域访问 public sta ...

  3. Apache Storm从一端读取实时数据的原始流

    Apache Storm从一端读取实时数据的原始流,并将其传递通过一系列小处理单元,并在另一端输出处理/有用的信息. 下图描述了Apache Storm的核心概念. 640?wx_fmt=png&am ...

  4. 【Revit API】梁的净高分析

    原理就是,先从梁的LocationCurve上取点,然后向板的上表面投影.如果有投影点,再从投影点(板上)向梁的底面投影,这时候如果有投影点的话就能得到距离了. 运用该分析的第一条件是梁是在板的上方, ...

  5. BZOJ3193 [JLOI2013]地形生成 【dp】

    题目链接 BZOJ3193 题解 注意\(key\)是小于 第一问,显然按高度降序排序,逐个插入 如果高度各不相同,那么之前插入的都比当前插入的\(i\)大,可插入的位置个数就确定了 由于存在高度相同 ...

  6. Advanced RESTClient插件安装 google浏览器

    在csdn下载插件,并解压. 然后在设置里找到扩展程序,打开并开启开发者模式,加载你刚刚解压的插件就可以. 我是用了蓝灯打开google的,成功后这样的

  7. 在ubuntu server上搭建Hadoop

    1. Java安装: Because everything work with java. $ sudo apt-get install openjdk-7-jdk 安装之后,可以查看java的版本信 ...

  8. Django中Celery http请求异步处理(四)

    Django中Celery http请求异步处理 本章延续celery之前的系列 1.settings配置 2.编写task jib_update_task任务为更新salt jid数据 3.url设 ...

  9. Redis记录-JAVA连接Redis

    在Java程序中使用Redis之前,需要确保在机器上安装了Redis的Java驱动程序和Java环境.可以先在将Java电脑上并配置好环境. 安装 现在,让我们看看如何设置Redis Java驱动程序 ...

  10. postman提取接口的返回值及动态设置变量(一)

    一.提取接口返回值   1.当返回值是返回JSON时 let json = JSON.parse(responseBody); // responseBody是包含整个返回内容的字符串 let foo ...