#include<bits/stdc++.h>
using namespace std;
int n,m,l,t;
int a[1307][137][67];
int vis[1307][137][67];
typedef struct{
    int x,y,z;
}node;
int xx[6]={0,0,0,0,1,-1};
int yy[6]={0,0,1,-1,0,0};
int zz[6]={1,-1,0,0,0,0};
node p;
int bfs(int x,int y,int z){
    queue<node>q;
    vis[x][y][z]=1;
    p.x=x;
    p.y=y;
    p.z=z;
    q.push(p);
    int sum=0;
    while(!q.empty()){
        node tmp=q.front();
        q.pop();
        sum++;
        for(int i=0;i<6;++i){
            int tx=tmp.x+xx[i];
            int ty=tmp.y+yy[i];
            int tz=tmp.z+zz[i];
            if(tx>0&&tx<=n&&ty>0&&ty<=m&&tz>0&&tz<=l&&a[tx][ty][tz]&&!vis[tx][ty][tz]){
                p.x=tx;
                p.y=ty;
                p.z=tz;
                q.push(p);
                vis[tx][ty][tz]=1;
            }
        }
    }
    if(sum>=t)
        return sum;
    return 0;
}
int main(){
    std::ios::sync_with_stdio(false);
    cin>>n>>m>>l>>t;
    for(int i=1;i<=l;++i)
        for(int j=1;j<=n;++j)
            for(int k=1;k<=m;++k)
                cin>>a[j][k][i];
    int ans=0;
    for(int i=1;i<=l;++i)
        for(int j=1;j<=n;++j)
            for(int k=1;k<=m;++k)
                if(a[j][k][i]&&!vis[j][k][i])
                    ans+=bfs(j,k,i);
    cout<<ans;
    return 0;
}

The Largest Generation (25)(BFS)(PAT甲级)的更多相关文章

  1. PAT Advanced 1094 The Largest Generation (25) [BFS,DFS,树的遍历]

    题目 A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level ...

  2. PTA甲级1094 The Largest Generation (25分)

    PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...

  3. pat1094. The Largest Generation (25)

    1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  4. PAT (Advanced Level) Practise - 1094. The Largest Generation (25)

    http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...

  5. 【PAT甲级】1094 The Largest Generation (25 分)(DFS)

    题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...

  6. PAT (Advanced Level) 1094. The Largest Generation (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  7. PAT练习——1094 The Largest Generation (25 point(s))

    题目如下: #include<iostream> #include<vector> #include<algorithm> using namespace std; ...

  8. 1094. The Largest Generation (25)

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...

  9. 1006.Sign in and Sign out(25)—PAT 甲级

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

随机推荐

  1. phalcon: 按年分表的model怎么建?table2017,table2018...相同名的分表模型怎么建

    phalcon: 按年分表的model怎么建?table2017,table2018...相同名的分表模型怎么建 场景:当前有一张表:Ntime,因为表太大了,考虑要分表: Ntime2017 Nti ...

  2. Spring Boot -- actuator

    Spring Boot有四大神器,分别是auto-configuration.starters.cli.actuator,本文主要讲actuator.actuator是spring boot提供的对应 ...

  3. Tomcat启动分析(我们为什么要配置CATALINA_HOME环境变量)

    原文:http://www.cnblogs.com/heshan664754022/archive/2013/03/27/2984357.html Tomcat启动分析(我们为什么要配置CATALIN ...

  4. java基础回顾之IO

    Java的IO 是Java运用重要部分之一,涉及到的内容也比较多,容易混淆,一段时间不用,可能就会遗忘,要时常回顾记忆一下: (图片来源于网络) Java 流在处理上分为字符流和字节流. 字符流处理的 ...

  5. bzoj 4044: Virus synthesis 回文自动机

    题目大意: 你要用ATGC四个字母用两种操作拼出给定的串: 将其中一个字符放在已有串开头或者结尾 将已有串复制,然后reverse,再接在已有串的头部或者尾部 一开始已有串为空.求最少操作次数. le ...

  6. node-webkit开发基本步骤

    详情请查看:http://www.heiboard.com/?p=2091

  7. POJ1456:Supermarket

    浅谈堆:https://www.cnblogs.com/AKMer/p/10284629.html 题目传送门:http://poj.org/problem?id=1456 把物品按照时间排序,显然\ ...

  8. debian软件安装和卸载

    用root身份执行如下命令: dpkg -l |grep "^rc"|awk '{print $2}' |xargs aptitude -y purge dpkg是Debian P ...

  9. java--序列化及其算法透析

    有关Java对象的序列化和反序列化也算是Java基础的一部分,下面对Java序列化的机制和原理进行一些介绍. Java序列化算法透析 Serialization(序列化)是一种将对象以一连串的字节描述 ...

  10. 【转】Pro Android学习笔记(十八):用户界面和控制(6):Adapter和AdapterView

    目录(?)[-] SimpleCursorAdapter 系统预置的layout ArrayAdapter 动态数据增插删排序 自定义TextView风格 其他Adapter AdapterView不 ...