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 ...
随机推荐
- Spring+Shiro的踩坑
今天想给某个Service的某些方法添加Cache,这个记为A,用的springboot,照常在方法上加上Cacheable注解,测试缓存生效,搞定.然后再在第二个Service,记为B,添加Cach ...
- 新手入门django本地化服务
自动化安装 #更新依赖库 pip install --upgrade setuptools #安装指定的版本 pip install Django==2.0.4 文 ...
- 函数的if--while流程控制
一.流程控制---if 1.if条件判断 age=18 hight=1.70 sex="female" is_beautiful=True if sex=="female ...
- Ch02 课堂作业
测试一:运行结果: 测试二:运行结果: 测试三:运行结果:
- Git入门——本地版本库操作
作为一个一直用SVN的家伙,深深地感到了自己在版本控制工具上的落伍.... 首先必须强调的是: Git与Github不是一回事. Git是目前世界上最先进的分布式版本控制系统,于2005年被linux ...
- 一个基于Net 的CMS -- Umbraco CMS
一个基于Net 的CMS -- Umbraco CMS: https://umbraco.com/ Sitecore 和 EPiServer http://www.bubuko.com/i ...
- Lua“控制”C
[前言] Lua语言本身是一个功能非常有限,而比较单调的语言,而且标准库也非常的平庸,它的NB之处就在于,它能和C.C++等高级语言完美“私通”.我们可以使用C.C++语言去给Lua写一个完美的库,让 ...
- Misc杂项隐写题writeup
MISC-1 提示:if you want to find the flag, this hint may be useful: the text files within each zip cons ...
- 【原创】大数据基础之Hadoop(3)yarn数据收集与监控
yarn常用rest api 1 metrics # curl http://localhost:8088/ws/v1/cluster/metrics The cluster metrics reso ...
- Jedis
需要把jedis依赖的jar包添加到工程中 连接单机版 // 第一步:创建一个Jedis对象.需要指定服务端的ip及端口. Jedis jedis = new Jedis("192.168. ...