题目https://pintia.cn/problem-sets/994805342720868352/problems/994805375457411072

题意:

求三维的连通块

思路:

简单bfs

 #include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue> #define inf 0x7fffffff
using namespace std;
typedef long long LL;
typedef pair<string, string> pr; int m, n, l, t;
struct node{
int x, y, z;
node(){
}
node(int _x, int _y, int _z){
x = _x;
y = _y;
z = _z;
}
}; int dx[] = {, , , , , -};
int dy[] = {, -, , , , };
int dz[] = {, , , -, , };
bool space[][][];
bool vis[][][];
int tot = ; bool check(int i, int j, int k)
{
if(i < || i >= m || j < || j >= n || k < || k >= l)return false;
else return true;
} void bfs(int x, int y, int z)
{
queue<node>que;
que.push(node(x, y, z));
vis[x][y][z] = true;
int cnt = ;
while(!que.empty()){
node now = que.front();que.pop();
for(int i = ; i < ; i++){
int a = now.x + dx[i], b = now.y + dy[i], c = now.z + dz[i];
if(check(a, b, c) && !vis[a][b][c] && space[a][b][c]){
que.push(node(a, b, c));
vis[a][b][c] = true;
cnt++;
}
}
}
if(cnt >= t){
tot += cnt;
}
} int main()
{
scanf("%d%d%d%d", &m, &n, &l, &t);
for(int k = ; k < l; k++){
for(int i = ; i < m; i++){
for(int j = ; j < n; j++){
scanf("%d", &space[i][j][k]);
}
}
} for(int k = ; k < l; k++){
for(int i = ; i < m; i++){
for(int j = ; j < n; j++){
if(!vis[i][j][k] && space[i][j][k])
bfs(i, j, k);
}
}
}
printf("%d\n", tot);
return ;
}

PAT甲级1091 Acute Stroke【三维bfs】的更多相关文章

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

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

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

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

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

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

  4. PAT甲题题解-1091. Acute Stroke (30)-BFS

    题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...

  5. PAT 1091. Acute Stroke (bfs)

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

  6. 1091. Acute Stroke (30)

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

  7. 1091 Acute Stroke

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

  8. 1091 Acute Stroke (30)(30 分)

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

  9. 【PAT甲级】1091 Acute Stroke (30 分)(BFS)

    题意: 输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小.输出一共有多少个单元满足所在联通块大小大于等于T. tr ...

随机推荐

  1. 两个Html页面之间值得传递

    传值的页面:<a href='stockProductInfo.html?prdId="+v.prdID+"' target='_blank'></html> ...

  2. django drf 基础学习2

    DRF基本程序调用一 models初步编写  1 编写model.py    from django.db import models 导入    class dbinfo(models.Model) ...

  3. python的request包

    1,request包基本用法 import requests a=requests.get("http://www.baidu.com")print a.text #以文本形式打印 ...

  4. 「luogu3313」[SDOI2014] 旅行

    题目大意 :有 n 个城市连成一棵树, 每个城市有两个关键字, 一个是该城市的宗教, 另一个是城市的评级;旅行者要在城市间旅行, 他只会在和自己宗教相同的城市留宿;维护四个树上操作 { 1. “CC ...

  5. hiho 1098 最小生成树二·Kruscal算法 (最小生成树)

    题目: 时间限制:10000ms 单点时限:1000ms 内存限制:256MB   描述 随着小Hi拥有城市数目的增加,在之间所使用的Prim算法已经无法继续使用了——但是幸运的是,经过计算机的分析, ...

  6. ubuntu 16.04扩充root 分区

    ubuntu使用过程中,提示root分区剩余空间不足,剩余200多M时还可以进行一些操作,剩余几M时拷贝等命令都不能够执行. 扩充root分区步骤如下: 1.查看root分区所在位置: 命令: sud ...

  7. LINUX系统VMSTAT命令详解

    linux系统vmstat命令详解 [转自 https://www.cnblogs.com/wensiyang0916/p/6514820.html] vmstat 1    1表示每秒采集一次vms ...

  8. js检测数据类型四种办法

    面试题中经常会考js数据类型检测,今天我来分享一下js中常用的四种方法判断数据类型,欢迎指点更正. 废话不多说,直入正题. 1.typeof console.log(typeof "&quo ...

  9. javascript事件委托的原理与实现

    事件委托 事件流 捕获:查找目标元素: 目标:执行目标的事件: 冒泡:依次执行祖先元素的事件. onmouseenter和onmouseleave不支持冒泡: onmouseover和onmouseo ...

  10. 将日志备份推送到s3存储上

    1.将日志备份推送到s3存储上 #!/bin/sh # 此脚本实现将/usr/local/netqin/boss/netqin/logs/BOSS_ContentServer/BOSS_AD_SDK ...