PAT 甲级 1091 Acute Stroke

PAT 甲级 1091 Acute Stroke

#include <bits/stdc++.h>
using namespace std;

int M,N,L,T;int ans=0;
int mp[1300][130][62];
bool in_q[1300][130][62];

struct Node{
    int x,y,z;
};
int pos[6][3]={{1,0,0},{0,1,0},{-1,0,0},{0,-1,0},{0,0,1},{0,0,-1}};
bool NeedToBeVisited(Node& n)
{
    if(n.x<0||n.x>=M) return false;
    if(n.y<0||n.y>=N) return false;
    if(n.z<0||n.z>=L) return false;
    if(mp[n.x][n.y][n.z]==0||in_q[n.x][n.y][n.z]==true) return false;
    else return true;
}

int BFS(int x,int y,int z)
{
    int ans=0;
    queue<Node> q;
    Node tmp{x,y,z};
    q.push(tmp);
    in_q[x][y][z]=true;
    
    while(!q.empty()){
        Node now=q.front();q.pop();++ans;
        for(int i=0;i<6;++i){
            Node next=now;
            next.x+=pos[i][0],next.y+=pos[i][1],next.z+=pos[i][2];
            if(NeedToBeVisited(next)){
                q.push(next);in_q[next.x][next.y][next.z]=true;
            }
        }
    }
    return ans>=T?ans:0;
}


int main() {
#ifdef LOCAL
    //freopen("input.txt","r",stdin);
#endif
    memset(mp,0,sizeof(mp));
    memset(in_q,false,sizeof(in_q));
    
    
    cin>>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){
                cin>>mp[i][j][k];
            }
    }
    for(int k=0;k<L;++k){
        for(int i=0;i<M;++i)
            for(int j=0;j<N;++j){
                if(mp[i][j][k]==1&&in_q[i][j][k]==false)
                    ans+=BFS(i,j,k);
            }
    }
    cout<<ans<<endl;

}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值