对于坐标平面的bfs模板题~

#include<bits/stdc++.h>
using namespace std;
const int maxn=;
bool visit[][][]={false};
int adj[][][];
int n,m,l,K;
int X[]={,,,-,,};
int Y[]={,,,,-,};
int Z[]={,,,,,-};
struct node {
int x,y,z;
};
bool judge (int x,int y,int z) {
if (x>=n||x<||y>=m||y<||z>=l||z<)
return false;
if (adj[x][y][z]==) return false;
if (visit[x][y][z]==true) return false;
return true;
}
int bfs (int x,int y,int z) {
queue<node> q;
q.push({x,y,z});
int cnt=;
visit[x][y][z]=true;
while (!q.empty()) {
node now=q.front();
q.pop();
cnt++;
for (int i=;i<;i++) {
int tx=now.x+X[i];
int ty=now.y+Y[i];
int tz=now.z+Z[i];
if (judge(tx,ty,tz)) {
q.push({tx,ty,tz});
visit[tx][ty][tz]=true;
//cnt++;
}
}
}
if (cnt>=K) return cnt;
return ;
}
int main () {
scanf ("%d %d %d %d",&n,&m,&l,&K);
for (int i=;i<l;i++)
for (int j=;j<n;j++)
for (int k=;k<m;k++)
scanf ("%d",&adj[j][k][i]);
int cnt=;
for (int i=;i<l;i++)
for (int j=;j<n;j++)
for (int k=;k<m;k++)
if (visit[j][k][i]==false&&adj[j][k][i]==) cnt+=bfs(j,k,i);
printf ("%d\n",cnt);
return ;
}

PAT A1091 Acute Stroke的更多相关文章

  1. PAT甲级——A1091 Acute Stroke【30】

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  2. A1091. Acute Stroke

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  3. PAT 1091 Acute Stroke [难][bfs]

    1091 Acute Stroke (30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the ...

  4. PAT 1091. Acute Stroke (bfs)

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  5. PAT_A1091#Acute Stroke

    Source: PAT A1091 Acute Stroke (30 分) Description: One important factor to identify acute stroke (急性 ...

  6. 【PAT】1091 Acute Stroke(30 分)

    1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...

  7. 1091. Acute Stroke (30)

    题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...

  8. PAT1091:Acute Stroke

    1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...

  9. pat1091. Acute Stroke (30)

    1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...

随机推荐

  1. 使用docker容器时遇到的2个问题

    最近项目在centOS7服务器上用docker部署了几个服务,在运行的时候发现,总是过一段时间,容器内的根目录就变为只读而无法写入了. 经过调查都是因为docker/devicemapper/devi ...

  2. 【C语言】用函数实现两个数排序(指针作函数参数)

    原理就不讲了,这里用来理解指针的使用方法 #include <stdio.h> void fun(int* a,int* b) { int t; if(*a>=*b) { t = * ...

  3. 使用ltp4j碰到Can't find dependent libraries报错信息的问题解决

    项目中使用了哈工大的自然语言处理模块ltp4j,使用idea工具集成到项目中之后,在本机运行没有问题,一切正常.打成war包,部署到服务器上,使用的时候报错Can't find dependent l ...

  4. PHP 基础 自动类型转换之比较运算符

    <?php var_dump(' 123fg456'>=122); var_dump('some string' == 0); var_dump(123.0 == '123d456'); ...

  5. 6_3 矩阵链乘(UVa424)<用栈实现简单的表达式解析>

    假设你必须做A*B*C*D*E的运算,在这里A,B,C,D,E都是矩阵(matrix).由于矩阵相乘具有连接性(associative),所以相乘的顺序可以是任意的.然而所需要的基本乘法数却与不尽相同 ...

  6. vue使用过程中遇到的细节问题

    1. 在methods 中添加一个方法.如果这个方法使用箭头函数的话,箭头函数中的this不是当前的vue实例,所以通过this.xxx是获取不到实例上面的属性的,这时我们可以用函数的简写来获取到实例 ...

  7. opencv:图像卷积

    卷积基本概念 C++代码实现卷积 #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; u ...

  8. ACM-ICPC实验室20.2.19测试-图论

    B.Harborfan的新年拜访Ⅱ 就是一道tarjan缩点的裸题. 建图比较麻烦 以后遇到这种建图,先用循环把样例实现出来,再对着循环写建图公式 #include<bits/stdc++.h& ...

  9. Python学习(五)—— 集合和字符格式化

    数据类型和变量的总结 字符串 数字 列表 元组 字典 分类 1.可变不可变: 可变(即修改变量值以后id不改变):列表.字典 不可变(即修改变量值以后id改变):字符串.数字.元组 2.访问顺序: 直 ...

  10. CapsNet资源

    算法源码: https://github.com/xanderchf/pyCapsNet https://github.com/naturomics/CapsNet-Tensorflow 参考文章: ...