1091. Acute Stroke (30)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

  1. pat1091. Acute Stroke (30)

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

  2. 1091. Acute Stroke (30)

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

  3. A1091. Acute Stroke

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

  4. 【PAT】1091 Acute Stroke(30 分)

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

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

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

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

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

  7. PAT 1091. Acute Stroke (bfs)

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

  8. PAT_A1091#Acute Stroke

    Source: PAT A1091 Acute Stroke (30 分) Description: One important factor to identify acute stroke (急性 ...

  9. PAT甲级——A1091 Acute Stroke【30】

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

随机推荐

  1. 集群通信组件tribes之通道拦截器

    拦截器应该可以说是一个很经典的设计模式,它有点类似于过滤器,当某信息从一个地方流向目的地的过程中,可能需要统一对信息进行处理,如果考虑到系统的可扩展性和灵活性通常就会使用拦截器模式,它就像一个个关卡被 ...

  2. Saiku去掉登录模块

    1.修改applicationContext-saiku-webapp.xml <security:intercept-url pattern="/rest/**" acce ...

  3. jQuery的ajax使用

    一:jQuery.ajax语法基础 jQuery.ajax([options]) 概述:通过 HTTP 请求加载远程数据. jQuery 底层 AJAX 实现.简单易用的高层实现见 $.get, $. ...

  4. Select、Poll与Epoll比较

    (1)select select最早于1983年出现在4.2BSD中,它通过一个select()系统调用来监视多个文件描述符的数组,当select()返回后,该数组中就绪的文件描述符便会被内核修改标志 ...

  5. IOS微信分享功能简单实现

    PS:此文以简单实现功能为主,不足之前还望指点,大神勿喷. 在此之前如何申请微信认证的Key就不说了,公司一般会有人搞 1.首先下载微信SDK:微信SDK下载地址(更多关于微信SDK信息文档请访问官方 ...

  6. ruby轻松自删除代码

    因为windows的文件删除机制和unix like的不一样,so不保证如下代码能在windows中使用,哪位童鞋帮我在windows中测试一下也好啊! #!/usr/bin/ruby 5.times ...

  7. ruby中printf "%x"%-4为何会打印开头..

    先看一下ruby中printf "%x" % -4的返回结果: irb(main):134:0> printf "%x\n" % -4 ..fc 前面的. ...

  8. Bash的一些零星笔记

    1.变量带入操作符 在脚本中,使用变量前做检查是很重要的.通过代入操作符,可以实现这方面的功能.比如当变量未赋值时为变量赋默认值,以及更多内容: ${parameter:-默认为空}:当paramet ...

  9. JTA 分布式事务

    什么是JTA - 2009-07-25 18:31:06|  分类: 技术文章|举报|字号 订阅     什么是JTA? Java Transaction API(Java事务API) (JTA)Ja ...

  10. CSS的应用下

    样式继承: 就是父类的颜色如果变了,子类下的div(或者其他属性)会继承父类的. 参考代码: <!DOCTYPE html> <html lang="en"> ...