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, ...
随机推荐
- jQuery 开发一个简易插件
jQuery 开发一个简易插件 //主要内容 $.changeCss = function(options){ var defaults = { color:'blue', ele:'text', f ...
- 纯CSS的jQuery的气泡提示组件
1. [代码][JavaScript]代码 //调用说明//$(selector).bub($(selector) | string[, options]);//示例: $('#demo1').bub ...
- Source not found The source attachment does not contain the source for the file MethodBeforeAdvice.class
- 京东自营,你TM太坑了。
双12来了,京东自营好坑.昨天(12月6日)看的一条秋裤,89元,今天准备买,居然涨到了119,他大爷的. 京东你大爷的.
- linux系统配置之开机启动过程(centos)
1.开机流程如下: 2.BIOS BIOS是英文"Basic Input Output System"的缩略词,直译过来后中文名称就是"基本输入输出系统".其实 ...
- Log4j_学习_00_资源帖
一.log4j2 1. log4j使用教程详解(怎么使用log4j2) 2.Log4j2的基本使用 二.log4j 1.[转]最详细的Log4J使用教程 2.最详细的Log4j使用教程 3.log4j ...
- ajax stream 一边下载二进制数据一边处理
最近有在做 stream 下载,并且边下载 stream 边处理功能.解析二进制的功能.最初参考了 flv.js 的 flv stream 下载处理功能,发现他并没有使用的 XMLHttpReques ...
- 1_Command 游戏开发命令模式
A dead simple implementation looks like: ``` // simple void InputHandler::handleInput() { if (isPres ...
- leetcode 5 Longest Palindromic Substring(Manacher算法求最长回文串)
应用一下manacher算法就可以O(n)求出结果了.可以参考hdu3068 substr(start,length)函数是这样用的: substr 方法 返回一个从指定位置开始,并具有指定长度的子字 ...
- Java 时间和日期类型的 Hibernate 映射
以下情况下必须显式指定 Hibernate 映射类型 一个 Java 类型可能对应多个 Hibernate 映射类型. 例如: 如果持久化类的属性为 java.util.Date 类型, 对应的 Hi ...