题目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. Vue.js 技术揭秘(学习) vue流程

    new Vue() _init() mergeOptions $watch --> new Watch vm._render 生成VNode create diff patch vm._upda ...

  2. python3编程练习题

    记录一些基础编程练习题和一些遇见的坑 1)输出0到100的数字,如果数字是3的倍数输出Fizz,5的倍数输出Buzz.同时是3和5的倍数输出FizzBuzz,其他情况则打印原数字 for i in r ...

  3. 第一周——数据分析之表示 —— Numpy入门

    数据的维度 从一个数据到一组数据 一个数据:表达一个含义 一组数据:表达一个或者多个含义 维度:一组数据的组织形式 一维数据 由对等关系的有序或者无序数据构成,采用线性方式组织,对应列表.数组和集合等 ...

  4. 【原创】大叔问题定位分享(20)hdfs文件create写入正常,append写入报错

    最近在hdfs写文件的时候发现一个问题,create写入正常,append写入报错,每次都能重现,代码示例如下: FileSystem fs = FileSystem.get(conf); Outpu ...

  5. iOS 推荐几篇关于Objective-c 动态语言的文章

    http://www.cnblogs.com/Mr-Lin/p/5771969.html https://onevcat.com/2012/04/objective-c-runtime/ 我摘抄几句比 ...

  6. C#+EntityFramework编程方式详细之Model First

    Model First Model First模式即“模型优先”,这里的模型指的是“ADO.NET Entity Framework Data Model”,此时你的应用并没有设计相关数据库,在VS中 ...

  7. 八.nginx网站服务实践应用

    期中集群架构-第八章-期中架构nginx章节====================================================================== 01. web ...

  8. mysql配置文件参数详解

    (一) [client]port = 3306socket = /tmp/mysql.sock [mysqld]port = 3306socket = /tmp/mysql.sock basedir ...

  9. MySQL入门命令

    SQL(Structured Query Language) SQL是结构化查询语言,是一种用来操作RDBMS的数据库语言,当前关系型数据库都支持使用SQL语言进行操作,也就是说可以通过 SQL 操作 ...

  10. echart 标题配置

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...