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, ...
随机推荐
- java中properties
一.Java Properties类 Java中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件,各种语言都有自己所支持的配置文件,配置 ...
- Git教程及问题解析
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! Git教程 最近用git比较多,做出教程一份,供大家参考. 1. 安装Git,并配置环 ...
- hash算法打散存储文件
1.首先,为防止一个目录下面出现太多文件,所以使用hash算法打散存储 举例代码: int hashcode = filename.hashCode();//得到hashCode int dir1 = ...
- Javascript-- jQuery DOM篇(一)
DOM创建节点及节点属性 通过JavaScript可以很方便的获取DOM节点,从而进行一系列的DOM操作.但实际上一般开发者都习惯性的先定义好HTML结构,但这样就非常不灵活了. 浏览器提供的一些原生 ...
- python-编译安装Python2.7
yum中最新的也是Python 2.6.6,只能下载Python 2.7.5的源代码自己编译安装. 操作步骤如下: 1)下载并解压Python 2.7.9的源代码 cd /opt wget --no- ...
- SQL语言方方面面
1 数据库和SQL 1.1 数据库 DB, DBMS DBMS的种类: 层次性数据库, 关系型数据库, 非关系型数据库 RDBMS, 关系数据库管理系统 1.2 数据库的结构 RDBMS常见的系统结构 ...
- Convolutional Neural Networks for Visual Recognition 3
Gradient Computing 前面我们介绍过分类器模型一般包含两大部分,一部分是score function,将输入的原始数据映射到每一类的score,另外一个重要组成部分是loss func ...
- 本地windows安装memcached服务
1.安装到系统服务中: 在doc中:执行此软件 memcached.exe -d install(如果提示错误,要找到cmd.exe用管理员身份打开) 安装后在,服务里吗就有个服务了,如果没有启动,点 ...
- [转]nodejs中的process模块--child_process.exec
1.process是一个全局进程,你可以直接通过process变量直接访问它. process实现了EventEmitter接口,exit方法会在当进程退出的时候执行.因为进程退出之后将不再执行事件循 ...
- Poj_1008--Maya Calendar
一.Description 上周末,M.A. Ya教授对古老的玛雅有了一个重大发现.从一个古老的节绳(玛雅人用于记事的工具)中,教授发现玛雅人使用了一个一年有365天的叫做Haab的历法.这个Haab ...