1091. Acute Stroke (30)【搜索】——PAT (Advanced Level) Practise

题目信息

1091. Acute Stroke (30)

时间限制400 ms

内存限制65536 kB

代码长度限制16000 B

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

解题思路

六个方向进行搜索

AC代码

#include <cstdio>
#include <queue>
#include <map>
using namespace std;
bool mp[63][1300][130];
int m, n, l, t, v, s;

struct node{
    int x, y, z;
    node operator+(node& b){
        return node(x + b.x, y + b.y, z + b.z);
    }
    node(int a, int b, int c) : x(a), y(b), z(c){}
};
node dir[6] = {node(0, 0, -1), node(0, 0, 1), node(1, 0, 0), node(-1, 0, 0), node(0, 1, 0), node(0, -1, 0)};
void bfs(int x, int y, int z){
    queue<node> que;
    int cnt = 1;
    mp[z][y][x] = false;
    que.push(node(x, y, z));
    while (!que.empty()){
        node b = que.front();
        que.pop();
        for (int i = 0; i < 6; ++i){
            node c = b + dir[i];
            if (mp[c.z][c.y][c.x]){
                mp[c.z][c.y][c.x] = false;
                que.push(c);
                ++cnt;
            }
        }
    }
    if (cnt >= t){
        s += cnt;
    }
}
int main()
{
    scanf("%d%d%d%d", &m, &n, &l, &t);
    for (int k = 1; k <= l; ++k){
        for (int i = 1; i <= m; ++i){
            for (int j = 1; j <= n; ++j){
                scanf("%d", &v);
                mp[k][i][j] = (v == 1);
            }
        }
    }
    for (int k = 1; k <= l; ++k){
        for (int i = 1; i <= m; ++i){
            for (int j = 1; j <= n; ++j){
                if (mp[k][i][j]){
                    bfs(j, i, k);
                }
            }
        }
    }
    printf("%d\n", s);
    return 0;
}
时间: 2024-10-14 20:50:23

1091. Acute Stroke (30)【搜索】——PAT (Advanced Level) Practise的相关文章

【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

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

PAT甲级——1091 Acute Stroke (广度优先搜索BFS)

本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/94207638 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

1093. Count PAT&#39;s (25)【计数】——PAT (Advanced Level) Practise

题目信息 1093. Count PAT's (25) 时间限制120 ms 内存限制65536 kB 代码长度限制16000 B The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th c

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 Spec

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

BFS求连通块.递归会爆栈. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<stack> #include<vector> using namespace std; int M,N,L,T; int A[70][1300][133]; bo

1076. Forwards on Weibo (30)【树+搜索】——PAT (Advanced Level) Practise

题目信息 1076. Forwards on Weibo (30) 时间限制3000 ms 内存限制65536 kB 代码长度限制16000 B Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with follo

1103. Integer Factorization (30)【搜索+剪枝】——PAT (Advanced Level) Practise

题目信息 1103. Integer Factorization (30) 时间限制1200 ms 内存限制65536 kB 代码长度限制16000 B The K-P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K-P factoriz

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

题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写,想有没有别的办法.然而结果是,实在想不出别的办法了,所以还是尝试写写dfs.bfs. 一开始先用了dfs,最后两个样例段错误,估计是栈溢出了.之所以dfs栈溢出,因为dfs的时候每个状态都会存储在堆栈里,就好比dfs的第一个状态,一直保存到最后整个dfs结束.而bfs是存储在队列中,每次队列都会有状态取