美文网首页
Acute Stroke (30)

Acute Stroke (30)

作者: 刷爆服务器 | 来源:发表于2018-06-18 10:08 被阅读0次
    #include<iostream>
    #include<queue>
    using namespace std;
    struct node{
        int x,y,z;
    };
    int M,N,L,T;
    int ans=0;
    int arr[1300][130][70];
    bool visit[1300][130][70];
    int xx[6]={1,0,0,-1,0,0};
    int yy[6]={0,1,0,0,-1,0};
    int zz[6]={0,0,1,0,0,-1};
    bool judge(int x,int y,int z){
        if(x<0||x>=M||y<0||y>=N||z<0||z>=L) return false;
        if(arr[x][y][z]==0||visit[x][y][z]==true) return false;
        return true;
    }
    void BFS(int x,int y,int z){
        int cnt=0;
        node temp;
        temp.x=x;temp.y=y;temp.z=z;
        queue<node> q;
        q.push(temp);
        visit[x][y][z]=true;
        while(!q.empty()){
            node top=q.front();
            q.pop();
            cnt++;
            for(int i=0;i<6;i++){
                int tx=top.x+xx[i];
                int ty=top.y+yy[i];
                int tz=top.z+zz[i];
                if(judge(tx,ty,tz)){
                    temp.x=tx;temp.y=ty;temp.z=tz;
                    visit[tx][ty][tz]=true;
                    q.push(temp);
                }
            }
        }
        if(cnt>=T)
            ans+=cnt;
    }
    int main() {
        cin>>M>>N>>L>>T;
        for(int i=0;i<L;i++)
            for(int j=0;j<M;j++)
                for(int k=0;k<N;k++)
                    cin>>arr[j][k][i];
        for(int i=0;i<L;i++)
            for(int j=0;j<M;j++)
                for(int k=0;k<N;k++)
                    if(arr[j][k][i]==1&&visit[j][k][i]==false)
                        BFS(j,k,i);
        printf("%d",ans);
    }
    

    相关文章

      网友评论

          本文标题:Acute Stroke (30)

          本文链接:https://www.haomeiwen.com/subject/razgeftx.html