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

pat1091. Acute Stroke (30)

时间:2014-12-02 13:25:23      阅读:470      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

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.

bubuko.com,布布扣
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

提交代码

题意:有l 片slices 每片上由 n*m个 像素点, l 片slices是按次序从下往上或者从上往下, 三维空间里上下左右相邻的算一块,一块至少要包含t个像素点才能计入总数,求总数

dfs就好了,不过最后两个案例数据量比较大,会爆栈,要用队列来写

bubuko.com,布布扣
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
int m,n,l,T,volume,totVol;
bool mapp[70][1300][130];
struct Point
{
    int z,x,y;
    Point(){}
    Point(int z,int x,int y):z(z),x(x),y(y){}
};
void dfs(int z,int x,int y)
{
    //此方法最后两个案例段错误,原因是递归深度会大于100000
    if(mapp[z][x][y])
    {
        volume++;
        mapp[z][x][y]=false;
        if(z>0)dfs(z-1,x,y);
        if(z+1<l)dfs(z+1,x,y);
        if(x>0)dfs(z,x-1,y);
        if(x+1<m)dfs(z,x+1,y);
        if(y>0)dfs(z,x,y-1);
        if(y+1<n)dfs(z,x,y+1);
    }
}
void dfs_queue(int i,int j,int k)
{
    if(!mapp[i][j][k])return;
    queue<Point>p;
    p.push(Point(i,j,k));

    while(!p.empty())
    {
        int z=p.front().z;
        int x=p.front().x;
        int y=p.front().y;
        p.pop();
        if(mapp[z][x][y]){
            mapp[z][x][y]=false;
            volume++;
            if(z>0)p.push(Point(z-1,x,y));
            if(z+1<l)p.push(Point(z+1,x,y));
            if(x>0)p.push(Point(z  ,x-1,y));
            if(x+1<m)p.push(Point(z,x+1,y));
            if(y>0)p.push(Point(z,x,y-1));
            if(y+1<n)p.push(Point(z,x,y+1));
        }
    }
}
int main()
{
    while(~scanf("%d%d%d%d",&m,&n,&l,&T))
    {
        int x;
        for(int i=0;i<l;i++)
        {
            for(int j=0;j<m;j++)
            {
                for(int k=0;k<n;k++)
                {
                    scanf("%d",&x);
                    if(x)mapp[i][j][k]=true;
                    else mapp[i][j][k]=false;
                }
            }
        }
        totVol=0;
        for(int i=0;i<l;i++)
        {
            for(int j=0;j<m;j++)
            {
                for(int k=0;k<n;k++)
                {
                    volume=0;
                  //  dfs(i,j,k);
                    dfs_queue(i,j,k);
                    if(volume>=T)totVol+=volume;
                }
            }
        }
        printf("%d\n",totVol);
    }
    return 0;
}
PAT1091

 

pat1091. Acute Stroke (30)

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/kylehz/p/4137141.html

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