#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. 分享知识-快乐自己:Struts2 前台日期到后台的日期格式转换

    案例目录: 关键代码展示: DateConverter: package com.mlq.util; import com.opensymphony.xwork2.conversion.TypeCon ...

  2. vue2.0使用Sortable.js实现的拖拽功能

    简介 在使用vue1.x之前的版本的时候,页面中的拖拽功能,我在项目中是直接用的jQuery ui中的sortable.js,只是在拖拽完成后,在update的回调函数中又重新排序了存放数据的数组.但 ...

  3. php 数字小写转为大写的函数

    PHP把阿拉伯数字转换成中文,需要定义一个转换的算法: <?php /将数字转换为汉字,比如1210转换为一千二百一十 $num = "842105580";//九位数 fu ...

  4. struts2--标签取值

    OGNL的概念: OGNL是Object-Graph Navigation Language的缩写,全称为对象图导航语言,是一种功能强大的表达式语言,它通过简单一致的语法,可以任意存取对象的属性或者调 ...

  5. mfc设置鼠标状态OnSetCursor响应函数

    参考文章:1.https://bbs.csdn.net/topics/70084486 2.https://blog.csdn.net/wang15061955806/article/details/ ...

  6. IP通信中音频编解码技术与抗丢包技术概要

    此文较长,建议收藏起来看. 一.一个典型的IP通信模型 二.Server2Server技术分类 Server2Server这块也是一个专门的领域,这里只简单分个类. 1.同一国家相同运营商之间: 同一 ...

  7. dbcc练习1

    dbcc tranceon(2588,3604) dbcc ind() dbcc page()

  8. ACM学习历程—ZOJ3777 Problem Arrangement(递推 && 状压)

    Description The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem sett ...

  9. bzoj 3012: [Usaco2012 Dec]First! Trie+拓扑排序

    题目大意: 给定n个总长不超过m的互不相同的字符串,现在你可以任意指定字符之间的大小关系.问有多少个串可能成为字典序最小的串,并输出这些串.n <= 30,000 , m <= 300,0 ...

  10. BZOJ1345:[Baltic2007]序列问题

    浅谈栈:https://www.cnblogs.com/AKMer/p/10278222.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?id ...