【PAT甲级】1091 Acute Stroke (30 分)(BFS)
题意:
输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小。输出一共有多少个单元满足所在联通块大小大于等于T。
trick:
三元数组大小开小了。。。最后两个测试点答案错误,我是笨比。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int m,n,l,t;
int a[][][];
int vis[][][];
int ans[][][];
int xx[]={,,,,-,,};
int yy[]={,,,,,-,};
int zz[]={,,,,,,-};
typedef struct nod{
int x,y,z;
};
queue<nod>q;
void dfs(int x,int y,int z){
while(!q.empty()){
++ans[x][y][z];
nod now=q.front();
q.pop();
for(int i=;i<=;++i){
int tx=now.x+xx[i];
int ty=now.y+yy[i];
int tz=now.z+zz[i];
if(!vis[tx][ty][tz]&&a[tx][ty][tz]==){
nod node;
node.x=tx;
node.y=ty;
node.z=tz;
vis[tx][ty][tz]=;
q.push(node);
}
}
}
}
void clear(queue<nod>&q){
queue<nod>emp;
swap(q,emp);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>m>>n>>l>>t;
for(int i=;i<=l;++i)
for(int j=;j<=m;++j)
for(int k=;k<=n;++k)
cin>>a[i][j][k];
int sum=;
for(int i=;i<=l;++i)
for(int j=;j<=m;++j)
for(int k=;k<=n;++k)
if(a[i][j][k]==&&!vis[i][j][k]){
clear(q);
nod tamp;
tamp.x=i;
tamp.y=j;
tamp.z=k;
q.push(tamp);
vis[i][j][k]=;
dfs(i,j,k);
if(ans[i][j][k]>=t)
sum+=ans[i][j][k];
}
cout<<sum;
return ;
}
【PAT甲级】1091 Acute Stroke (30 分)(BFS)的更多相关文章
- PAT甲级1091 Acute Stroke【三维bfs】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805375457411072 题意: 求三维的连通块 思路: 简单b ...
- 【PAT】1091 Acute Stroke(30 分)
1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...
- 1091 Acute Stroke (30)(30 分)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- PAT甲级——A1091 Acute Stroke【30】
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 ...
- PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)
1080 Graduate Admission (30 分) It is said that in 2011, there are about 100 graduate schools ready ...
- PAT 甲级 1072 Gas Station (30 分)(dijstra)
1072 Gas Station (30 分) A gas station has to be built at such a location that the minimum distance ...
- PAT 甲级 1049 Counting Ones (30 分)(找规律,较难,想到了一点但没有深入考虑嫌麻烦)***
1049 Counting Ones (30 分) The task is simple: given any positive integer N, you are supposed to co ...
- PAT 甲级 1030 Travel Plan (30 分)(dijstra,较简单,但要注意是从0到n-1)
1030 Travel Plan (30 分) A traveler's map gives the distances between cities along the highways, to ...
随机推荐
- HTML列表,表格与媒体元素
一.无序列表 <ul> <li>无序列表</li> <li>有序列表</li> <li>自定义列表</li> < ...
- mediasoup-demo解析-服务端
1.启动server npm start启动服务,会执行脚本: "start": "DEBUG=${DEBUG:='*mediasoup* *INFO* *WARN* * ...
- Python中的模块简单认识
将自己定义的方法,变量存放在文件中,为一些脚本或者交互式的解释器实例使用,这个文件称为模块. 细说的话,模块可以分为四个通用类别: 1 使用python编写的.py文件(自定义模块) 2 已被编译为共 ...
- java基础之 开发环境配置
一.Window 第一步:下载JDK 首先,我们需要下载java开发工具包JDK,下载地址:http://www.oracle.com/technetwork/java/javase/download ...
- 根据wsdl生成soap请求格式
本文链接:https://blog.csdn.net/a_Little_pumpkin/article/details/84725118根据wsdl文件如何生成soap请求的格式呢?使用最方便的工具S ...
- 开发笔记-记一个基础logback配置
<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true&q ...
- 用fgets()和fputs()代替gets()和puts()
gets()和puts不安全,有些平台会报错,如pat. gets输入字符串时,不进行数组下标的检查,也就是说当你的数组长度是n时,输入超过该长度的字符串的时候,编译不会出错,但是运行的时候会出现数组 ...
- mysql学习笔记(1)
以下笔记并不系统,只是针对遇到的问题和特别的点记录一下: 数据类型: 1.mysql小数存储数据类型 有float double decimal ,前两个不属于精确类型,不推荐使用,一般生产库亦不会使 ...
- testng实现代码和数据分层
todo: 参考: https://www.cnblogs.com/znicy/p/6534893.html
- 一些关于网页标题的动态js特效
1.当转换页面时,标题改变 <script> document.addEventListener('visibilitychange',function(){ if(document.vi ...