码迷,mamicode.com
首页 > 其他好文 > 详细

PAT-ADVANCED-1091-Acute Stroke

时间:2015-09-08 23:31:14      阅读:344      评论:0      收藏:0      [点我收藏+]

标签:

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

 当连通集的大小大于T的时候才参与统计!

使用DFS会有些测试点过不去,改用BFS.6个if那里实在太丑了,可以改用一个数组来表示的。

技术分享
#include <bits/stdc++.h>
#define MAXM 1300
#define MAXN 130
#define MAXL 60+5
using namespace std;
struct node{
    int x, y, z;
};
int m, n, l, t;
int res = 0;
int arr[MAXL][MAXM][MAXN];
void solve(int k, int i, int j);
bool checkBorder(int x, int y, int z);
int main(){
    scanf("%d%d%d%d", &m, &n, &l, &t);
    for(int k = 0; k < l; ++k){
        for(int i = 0; i < m; ++i){
            for(int j = 0; j < n; ++j){
                scanf("%d", &arr[k][i][j]);
            }
        }
    }
    for(int k = 0; k < l; ++k){
        for(int i = 0; i < m; ++i){
            for(int j = 0; j < n; ++j){
                if(arr[k][i][j]){
                    solve(k, i, j);
                }
            }
        }
    }
    printf("%d\n", res);
    return 0;
}

void solve(int k, int i, int j){
    queue<node> q;
    q.push({i, j, k});
    arr[k][i][j] = 0;
    int cnt = 0;
    while(!q.empty()){
        node top = q.front();
        cnt++;
        q.pop();
        if(checkBorder(top.x+1, top.y, top.z)){
            q.push({top.x+1, top.y, top.z});
            arr[top.z][top.x+1][top.y] = 0;
        }
        if(checkBorder(top.x, top.y+1, top.z)){
            q.push({top.x, top.y+1, top.z});
            arr[top.z][top.x][top.y+1] = 0;
        }
        if(checkBorder(top.x, top.y, top.z+1)){
            q.push({top.x, top.y, top.z+1});
            arr[top.z+1][top.x][top.y] = 0;
        }
    }
    if(cnt >= t){
        res += cnt;
    }
}

bool checkBorder(int x, int y, int z){
    if(x >= m || x < 0 || y >= n || y < 0 || z >= l || z < 0){
        return false;
    }
    if(!arr[z][x][y]){
        return false;
    }
    return true;
}
CAPOUIS‘CODE

 

PAT-ADVANCED-1091-Acute Stroke

标签:

原文地址:http://www.cnblogs.com/capouis/p/4793259.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!