The Largest Generation (25)(BFS)(PAT甲级)
#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甲级)的更多相关文章
- 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 ...
- PTA甲级1094 The Largest Generation (25分)
PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...
- pat1094. The Largest Generation (25)
1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 ...
- 【PAT甲级】1094 The Largest Generation (25 分)(DFS)
题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...
- PAT (Advanced Level) 1094. The Largest Generation (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT练习——1094 The Largest Generation (25 point(s))
题目如下: #include<iostream> #include<vector> #include<algorithm> using namespace std; ...
- 1094. The Largest Generation (25)
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...
- 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, ...
随机推荐
- python第八篇:十分钟学会Flask
什么是Flask Flask是一个基于Python并且依赖于Jinja2模板引擎和Werkzeug WSGI服务的一个微型框架 Flask中包含一个轻量级的web 服务器主要用于在开发阶段测试使用 F ...
- http接口测试框架-python
简单分解一下 接口测试框架设计: 主入口 -> 遍历接口/用例 -> 发送请求+接收响应 ->结果的对比 -> 生成报告 ->发送email 分成几大类:主入口的py文件 ...
- poj2661 Factstone Benchmark(大数不等式同取对数)
这道题列出不等式后明显是会溢出的大数,但是没有必要写高精度,直接两边取对数(这是很简明实用的处理技巧)得: log2(n!)=log2(n)+log2(n-1)+...+log2(1)<=log ...
- java正则表达式匹配文本中想要的字符串
需求:获取一个本地文件中所有符合 $[MAKE_PACKAGE] 格式的字符串,并输出到另一个文件中. public static void main(String[] args) throws Ex ...
- C++0X 学习之 auto
auto并不是一个新关键词,是一个把旧关键词赋予新的作用,新的作用修饰变量声明,指示编译器根据变量的初始化表达式推导变量应有的类型.auto 声明的变量必须“在声明处完成初始化”,编译器才可根据初始化 ...
- 关于linux 安装 python pymssql模块
需要先安装freetds是一个开源的C程序库,它可以实现在Linux系统下访问操作微软的SQL数据库.可以用在Sybase的db-lib或者ct-lib库,在里面也包含了一个ODBC的库.允许许多应用 ...
- nvidia-docker 安装
1.安装docker 官方网址安装说明 https://docs.docker.com/install/linux/docker-ce/ubuntu/ 2.ubuntu 14.04/16.04/18. ...
- Android的缓存图片不在系统图库中显示的解决办法
Android的图库会在开机的时候扫描SD卡中的图片,视频等文件,有很多App的私有图片不想在图库中显示,就需要另外处理了. 解决办法:在缓存图片的文件夹中创建 .nomedia 文件. 1. &qu ...
- Muduo 多线程模型:一个 Sudoku 服务器演变
陈硕 (giantchen AT gmail) blog.csdn.net/Solstice Muduo 全系列文章列表: http://blog.csdn.net/Solstice/category ...
- BZOJ1218:[HNOI2003]激光炸弹
我对状态空间的理解:https://www.cnblogs.com/AKMer/p/9622590.html 题目传送门:https://www.lydsy.com/JudgeOnline/probl ...