对于坐标平面的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. github,gitlab的区别

    链接:https://blog.csdn.net/Xiamen_XiaoHong/article/details/83655447 总而言之:gitlab最优

  2. Go_file操作

    1. FileInfo package main import ( "os" "fmt" ) func main() { /* FileInfo:文件信息 in ...

  3. RAID 0实验:mdadm

    *独立冗余磁盘阵列---RAID0* RAID0: 把多块物理硬盘设备(至少两块)通过硬件或软件的方式串联在一起, 组成 一个大的卷组,并将数据依次写入到各个物理硬盘中.任意一块 硬盘发生故障将导致整 ...

  4. centos7的netca命令和netmgr命令、dbca命令等基础知识点

    netca命令: netmgr命令: dbca命令: database assistant  configuration 中的SGA 和PGA SGA:System Global Area是Oracl ...

  5. uni-app 去除顶部导航栏

    自学uni-app第一天,因为有一点点的小程序和vue的基础所以感觉对uni-app有一点点的亲切感,从今天呢开始着手从登录页学习uni-app,记录一些用到的知识点,欢迎大家一起学习. 启动页隐藏顶 ...

  6. 让 typora和word一样好用

    让 typora和word一样好用  :https://github.com/itcastWsy/typora_copy_images typora是一款支持实时预览的markdown编辑器,作者在使 ...

  7. 微信支付开发h5调用

    这两天做微信支付开发.碰到大坑.纠结死我了.好不容做完. 后台java:直接上代码:注意区分前后端的变量大小写... @RequestMapping(value = "/index" ...

  8. 安卓之视图View的基本属性

    一.在xml布局文件中常用的属性定义   (1)  id:指定该视图的编号   (2)  layout_width:指定该视图的宽度可以是具体的dp值:可以是match_parent,表示与上级视图一 ...

  9. 使用axios对安卓或者ios低版本兼容性处理

    原因:不支持ES6,无法使用promise 解决办法: 1.安装 es6-promise cnpm install es6-promise --save-dev 2.引入 es6-promise im ...

  10. @media screen 自适应笔记

    在css中使用@media screen 通过检索宽度 对应改变html中class的css属性. 1280分辨率以上(大于1200px) @media screen and (min-width:1 ...