PAT甲级1091 Acute Stroke【三维bfs】
题目: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】的更多相关文章
- PAT 1091 Acute Stroke [难][bfs]
1091 Acute Stroke (30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the ...
- 【PAT】1091 Acute Stroke(30 分)
1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...
- PAT甲级——A1091 Acute Stroke【30】
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- PAT甲题题解-1091. Acute Stroke (30)-BFS
题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...
- PAT 1091. Acute Stroke (bfs)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 1091. Acute Stroke (30)
题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...
- 1091 Acute Stroke
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 1091 Acute Stroke (30)(30 分)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 【PAT甲级】1091 Acute Stroke (30 分)(BFS)
题意: 输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小.输出一共有多少个单元满足所在联通块大小大于等于T. tr ...
随机推荐
- Java同步容器
一.为什么会出现同步容器 Java的集合框架中,主要有四大类别:List,Set,Queue,Map List,Set,Queue接口分别继承了Collection接口,Map本身是一个接口. 注意C ...
- iTOP-4412开发板-串口转接小板的使用文档
本文档介绍如何使用 迅为iTOP-4412 精英版如何使用串口转接板,串口小板如下所示.和串口转接板模块相关的资料如下:“iTOP-4412-Android-串口测试文档(升级版)_V2.X.zip” ...
- phpstudy 2016 切换Nginx+php7.0版本所需运行库 vc14 + 安装redis拓展
去微软官方下载vc14的运行库 链接:https://www.microsoft.com/en-us/download/details.aspx?id=48145 32位运行库 安装成功 切换版本成功 ...
- SQL server 存储过程中 列传行
select @exchange=exchange,@coupons_type=coupons_type - FLOOR(exchange))) from points_exchange_svc wh ...
- jenkins备份与恢复【转】
jenkins这里我通过thinbackup插件进行对jenkins的配置备份与恢复 1丶安装thinbackup插件 2丶系统管理选择thinbackup插件 3丶创建备份目录 mkdir /bac ...
- ubuntu 1604安装docker-ce 记录
以前在linux 内核为2.x的低版本中安装过docker,但是很多功能特性都无法使用,本次是在ubuntu 16.04上安装,记录安装过程,方便后续查阅. 一.安装前准备: 1. 安装包,允许 ap ...
- 【转载】PHP5.3 配置文件php.ini-development和php.ini-production的区别
引言 虽然现在PHP版本已经升级至7.*了,由于自己略懒,就在网上找了一篇略谈 php.ini-development 和 php.ini-production 区别的文章,重点是想要最后的那张表. ...
- Android开发之字体设置
默认字体 Android SDK自带了四种字体:"normal"“monospace",“sans”, “serif”,如下: 字体 看这四兄弟长的还是蛮像,我是看不 ...
- <?xml version="1.0" encoding="UTF-8"?> 的作用
version="1.0" 声明用的xml版本是1.0 encoding="UTF-8" 声明用xml传输数据的时候的字符编码,假如文档里面有中文,编码方式不是 ...
- verilog 仿真时读取txt文件
:]data; initial begin # clk =; clk = ~clk; end initial begin # rst=; # rst=; end :]data_sin[:]; //// ...