对于坐标平面的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. Windows引用opencv静态库

    参考博客:https://www.cnblogs.com/sysuzyq/p/6183568.html

  2. 利用tensorboard将数据可视化

    注:代码是网上下载的,但是找不到原始出处了,侵权则删 先写出visual类: class TF_visualizer(object): def __init__(self, dimension, ve ...

  3. Python入门,基本数据类型

    1.Python中的注释 单行注释:#注释内容 多行注释:三引号(单或者是双) ''' 注释内容 ''' """ 注释内容 """ 2.输入 ...

  4. 拿到别人的Django程序如何在本地RUN起来

    在Pycharm IDE下 Edit Configurations 1.检查Python interpreter 2.检查 Working directory 3.Settings 数据库配置

  5. java 面试题 高阶版

    1.hash 算法问题 hash(n) /服务器个数 hash 算法在服务器增加或者减少的时候,数据存取位置为发生变化: 什么是一致性hash算法? 一致性hash算法对2^32 取模,整个Hash空 ...

  6. scrapy import CrawlSpider 报错

    from scrapy.spider import CrawlSpider 报错 import module CrawlSpider error 看了下以前一直用的scrapy0.14.1 使用的是B ...

  7. centos7一步一步搭建docker tomcat 及重点讲解

    系统环境:centos7.7 (VMware中) image版本:tomcat:8-jdk8-openjdk (截止2020.01.10该系列版本) 安装步骤参考文章:https://www.jian ...

  8. php 基础 判断类型

    八.PHP中判断类型 is_bool():判断是否是布尔型 is_int().is_integer()和 is_long():判断是否为整型. is_float().is_double()和 is_r ...

  9. Python - __getattr__和__getattribute__的区别

    传送门 https://docs.python.org/3/reference/datamodel.html#object.__getattr__ https://docs.python.org/3/ ...

  10. pacman 包管理器相关设定

    pacman 包管理器相关设定 使用国内源 sudo pacman-mirrors -i -c China -m rank 设定 archlinuxcn 源 编辑/etc/pacman.conf,末尾 ...