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, ...
随机推荐
- window.onload 添加多个函数绑定
window.onload = function(){alert(2)} function addEvent (fun) { var old = window.onload; if(typeof ol ...
- yield生成器的经典案例
如何生成斐波那契數列 斐波那契(Fibonacci)數列是一个非常简单的递归数列,除第一个和第二个数外,任意一个数都可由前两个数相加得到.用计算机程序输出斐波那契數列的前 N 个数是一个非常简单的问题 ...
- 泛型,注解,反射配合优化BaseDao的猜想
package test; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.la ...
- struts2--标签取值
OGNL的概念: OGNL是Object-Graph Navigation Language的缩写,全称为对象图导航语言,是一种功能强大的表达式语言,它通过简单一致的语法,可以任意存取对象的属性或者调 ...
- pyget-资源与标签(Sprite、Label、Font)
Sprite精灵,是游戏中对具有动画作用功能的图片的爱称. 精灵,图标和字体等资源是不能够处理事件的,因为它们并不是继承自EventDispatcher.但是可以包含一个能够EventDispatch ...
- list dict set comprehension 列表推导式 (字典推导式,集合推导式)
从一个list生成新的list [ word.upper() for word in 'hellO worlD!' ] 简单的语法,如果不用list comprehension, 则要用更长的代码. ...
- Eclipse 反编译插件安装jad【转】
原文地址:http://tangmingjie2009.iteye.com/blog/1916992 Eclipse的反编译插件一直在用jad,感觉很不错. 刚下了个新版的eclipse,配置jad的 ...
- 多版本Python共存时pip给指定版本的python安装package的方法
在Linux安装了多版本Python时(例如python2.7和3.6),pip安装的包不一定是用户想要的位置,此时可以用 -t 选项来指定位置. 例如目标位置是/usr/local/lib/pyth ...
- HDU5438:Ponds(拓扑排序)
Ponds Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Sub ...
- 查看,上传crushmap命令
标签(空格分隔): ceph,ceph运维,crushmap 查看crushmap命令 从mon节点获取crushmap: # ceph osd getcrushmap -o crush.map 反编 ...