8.2 1091 Acute Stroke (30 分)(********)

#include <cstdio>
#include <queue>
using namespace std;
struct node
{
    int x;
    int y;
    int z;
}Node;
int n,m,l,t;
int matrix[1290][130][65];
bool inq[1290][130][65] = {false};
int ax[6] = {0,0,0,0,1,-1};
int ay[6] = {0,0,1,-1,0,0};
int az[6] = {1,-1,0,0,0,0};

bool judge(int x,int y,int z)
{

    if(x >= n || x < 0 || y >= m || y <0 || z>=l || z<0) return false;
    if(inq[x][y][z] == true || matrix[x][y][z] == 0) return false;

    return true;
}


int BFS(int x,int y,int z)
{
    int cn = 0;
    queue<node>q;
    node s;
    s.x = x;
    s.y = y;
    s.z = z;
    q.push(s);
    inq[x][y][z] = true;
    while(!q.empty())
    {
        node t = q.front();
        q.pop();
        cn++;
        for(int i = 0;i<6;i++)
        {
            int nx,ny,nz;
            nx = t.x + ax[i];
            ny = t.y + ay[i];
            nz = t.z + az[i];
            if(judge(nx,ny,nz))
            {
            //不能改变T不然会错
            	//t.x = x;
            	//t.y = y;
            	//t.z = z;
            	//q.push(t);
                s.x = nx;
                s.y = ny;
                s.z = nz;
                q.push(s);
                inq[nx][ny][nz] = true;
            }
        }
    }
    if(cn >= t)
        return cn;
    else
        return 0;
}
int main()
{
    freopen("in.txt","r",stdin);

    scanf("%d%d%d%d",&n,&m,&l,&t);

    for(int z = 0;z<l;z++)
    {
        for(int i=0;i<n;i++)
        {
            for(int j = 0;j<m;j++)
            {
                scanf("%d",&matrix[i][j][z]);
            }
        }
    }
    int ans = 0;
    for(int z = 0;z<l;z++)
    {
        for(int i=0;i<n;i++)
        {
            for(int j = 0;j<m;j++)
            {
                if(matrix[i][j][z] == 1 && inq[i][j][z] == false)
                {
                    ans += BFS(i,j,z);
                }
            }
        }
    }
    printf("%d\n",ans);

    return 0;
}

发布了111 篇原创文章 · 获赞 4 · 访问量 3225

猜你喜欢

转载自blog.csdn.net/qq_15556537/article/details/99705094
今日推荐