#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. Shiro身份认证---转

    目录 1. Shro的概念 2. Shiro的简单身份认证实现 3. Shiro与spring对身份认证的实现 前言: Shiro 可以非常容易的开发出足够好的应用,其不仅可以用在 JavaSE 环境 ...

  2. Progressive Web App是一个利用现代浏览器的能力来达到类似APP的用户体验的技术——不就是chrome OS吗?

    什么是Progressive Web App? Progressive Web App是一个利用现代浏览器的能力来达到类似APP的用户体验的技术,由Google实现,让浏览器打开的网址像APP一样运行 ...

  3. centos 静态拨号

    本人系统centos6.5:虚拟机太丑,固ssh. centos的与联网相关的配置文件在 $ /etc/sysconfig/network-scripts DHCP方式-联网 打开文件 $ vim / ...

  4. 通知消息与ON_NOTIFY

    1.通知消息一般是由子控件发出,由父窗口响应,因此响应函数的位置在父窗口内. 2.通知消息发送给父窗口的是通知码,即WM_NOTIFY消息(但为了区分方便不同的消息有不同的名称,但都是以WM_NOTI ...

  5. codeforces 622A A. Infinite Sequence (二分)

    A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. 批量处理JDBC语句提高处理速度

    当需要成批插入或者更新记录时.可以采用Java的批量更新机制,这一机制允许多条语句一次性提交给数据库批量处理.通常情况下比单独提交处理更有效率 JDBC的批量处理语句包括下面两个方法: –      ...

  7. Statement

    题目大意 给定一棵基环外向树,和若干组询问,对于每次独立的询问都指定一些起点和一些终点,你删去一些边,使得从任意起点出发都无法到达终点,并让删去的边的编号的最小值最大,求这个最大的最小值. 题解 不难 ...

  8. bzoj 2565: 最长双回文串 回文自动机

    题目: Description 顺序和逆序读起来完全一样的串叫做回文串.比如acbca是回文串,而abc不是(abc的顺序为"abc",逆序为"cba",不相同 ...

  9. nodejs调试:node-inspector

    基于Chrome浏览器的调试器 既然我们可以通过V8的调试插件来调试,那是否也可以借用Chrome浏览器的JavaScript调试器来调试呢?node-inspector模块提供了这样一种可能.我们需 ...

  10. Python:更改字典的key

    思路:先删除原键值对,保存值,然后以新键插入字典 格式:dict[newkey] = dict.pop(key) d = {'a':1, 'aa':11} d['b'] = d.pop('a') d[ ...