PAT1091:Acute Stroke
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 by 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 by 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 思路 由题意,M行N列的矩阵表示一片脑部切图,矩阵中的值——0表示该位置一切正常,1表示该位置为肿瘤区,L表示脑部切图的片数,由此构建了一个M、N、L的三维的矩阵。
现在让你确定统计肿瘤区的个数,注意只有上下前后左右相邻的肿瘤区且这些相邻的区域个数必须不小于T才能被统计。
归根结底其实就是一个3D图的连通分量问题,即统计每一个节点数不小于T的连通分量的节点数之和。
用BFS或者DFS都行,这里用BFS更好,DFS递归可能会栈溢出。 代码
#include<iostream>
#include<queue>
using namespace std;
/*
坐标系如下
xxxxxxxxxxxxxxxxxx + →
z
z
z
z
z
z
z
+
↓
y轴垂直屏幕射出 */
class node
{
public:
int x,z,y;
node(int a,int b, int c){x = a;z = b;y = c;}
};
//6个方向分别为上下前后左右
int X[6] = {0,0,0,0,-1,1};
int Y[6] = {1,-1,0,0,0,0};
int Z[6] = {0,0,1,-1,0,0};
int graph[1290][130][65];
bool visit[1290][130][65];
int M,N,L,T; // z x y T bool check(int x,int z,int y)
{
if(x < 0 || z < 0 || y < 0 || x >= N || z >= M || y >= L)
return false;
if(graph[x][z][y] == 0 || visit[x][z][y])
return false;
return true;
} int bfs(int x,int z,int y)
{
int cnt = 0;
node tmp(x,z,y);
queue<node> q;
q.push(tmp);
visit[x][z][y] = true;
while(!q.empty())
{
node f = q.front();
q.pop();
cnt++;
for(int i = 0;i < 6;i++)
{
int newx = f.x + X[i];
int newz = f.z + Z[i];
int newy = f.y + Y[i];
if(check(newx,newz,newy))
{
visit[newx][newz][newy] = true;
tmp.x = newx;
tmp.y = newy;
tmp.z = newz;
q.push(tmp);
}
}
}
if(cnt >= T)
return cnt;
else
return 0;
} int main()
{
cin >> M >> N >> L >> T;
for(int y = 0;y < L;y++)
{
for(int z = 0; z < M;z++)
{
for(int x = 0;x < N;x++)
{
cin >> graph[x][z][y];
visit[x][z][y] = false;
}
}
}
int res = 0;
for(int y = 0;y < L;y++)
{
for(int z = 0; z < M;z++)
{
for(int x = 0;x < N;x++)
{
if(graph[x][z][y] == 1 && !visit[x][z][y])
res += bfs(x,z,y);
}
}
} cout << res << endl; }
PAT1091:Acute Stroke的更多相关文章
- pat1091. Acute Stroke (30)
1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...
- 1091. Acute Stroke (30)
题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...
- 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 ...
- 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
Source: PAT A1091 Acute Stroke (30 分) Description: One important factor to identify acute stroke (急性 ...
- PAT甲级——A1091 Acute Stroke【30】
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
随机推荐
- Android开源项目——设置图文居中的按钮 IconButton
本文介绍一下一个小众的开源项目--IconButton. 本文原创,转载请注明出处: http://blog.csdn.net/maosidiaoxian/article/details/435602 ...
- 一个可以拖动的自定义Gridview代码
这个可以拖动的gridview继承于gridview,所以,用法和gridview一样, 代码如下: public class DragGridView extends GridView { priv ...
- 【matlab编程】Matlab版扫雷
我发现有些人平常闲着的时候会玩window自带的游戏,其中最常见的就是扫雷和纸牌.本来想用matlab编写全自动扫雷程序用来作弊,可是后来发现扫雷问题是NP完全问题(正如:旅行商NP难问题一样不能被解 ...
- U盘无法安装win10提示Your PC/Device needs to be repaired
前一阵子把笔记本自带的win8升级到8.1,又升级到win10. 差不多有一个月没有开机,前几天开机后进不了系统,出现如下图的提示.买电脑自带的win8是正版的,但升级到win10后就过期了,也真是坑 ...
- 【Java编程】Java基本数据类型
在较前面的一篇博文<C/C++基本数据类型>中,我主要介绍了c/c++的基本数据类型.我们知道C语言没有具体规定各类数据类型所占内存的字节数,只要求long型数据长度不小于int型,sho ...
- ANDROID 中设计模式的采用--结构型模式
结构型模式中的适配器模式.外观模式.装饰模式.代理模式都属于包装模式,都是对另外的类或对象的包装,只是各自的意图不同. 适配器模式通过对另外的类或对象的包装,将其接口转换为用户期望 ...
- bash下如何使用bind[En]
You can determine the character sequence emitted by a key by pressing Ctrl-v at the command line, th ...
- UNIX/Linux C 程序员需要掌握的七种武器
我是一名普通的软件工程师,不是什么技术大牛.这篇文章所提到的"七种武器"只是我这些年工作经验的一点体会和感悟,如果有错误的地方,还请大家指正. (一)C语言 作为一名C程序员,熟练 ...
- LeetCode之旅(19)-Power of Two
题目 Given an integer, write a function to determine if it is a power of two. Credits: Special thanks ...
- python下实现二叉堆以及堆排序
python下实现二叉堆以及堆排序 堆是一种特殊的树形结构, 堆中的数据存储满足一定的堆序.堆排序是一种选择排序, 其算法复杂度, 时间复杂度相对于其他的排序算法都有很大的优势. 堆分为大头堆和小头堆 ...