PAT (Advanced Level) 1091. Acute Stroke (30)
BFS求连通块。递归会爆栈。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std; int M,N,L,T;
int A[][][];
bool f[][][]; int dir[][]={
{,,},
{,,-},
{,,},
{,-,},
{,,},
{-,,}
}; struct Point
{
int a,b,c;
Point (int aa,int bb,int cc)
{
a=aa; b=bb; c=cc;
}
}; int Find(int a,int b,int c)
{
int res=;
queue<Point>q; Point p(a,b,c);
q.push(p);
f[a][b][c]=; while(!q.empty())
{
res++;
Point head=q.front(); q.pop();
for(int i=;i<;i++)
{
int na=head.a+dir[i][];
int nb=head.b+dir[i][];
int nc=head.c+dir[i][]; if(na>L||na<) continue;
if(nb>M||nb<) continue;
if(nc>N||nc<) continue; if(A[na][nb][nc]==) continue;
if(f[na][nb][nc]==) continue; Point p(na,nb,nc);
q.push(p);
f[na][nb][nc]=;
}
}
return res;
} int main()
{
memset(A,,sizeof A);
memset(f,,sizeof f);
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",&A[k][i][j]);
int sum=;
for(int k=;k<=L;k++)
for(int i=;i<=M;i++)
for(int j=;j<=N;j++)
{
if(A[k][i][j]==) continue;
if(f[k][i][j]==) continue;
int res=Find(k,i,j);
if(res>=T) sum=sum+res;
}
printf("%d\n",sum); return ;
}
PAT (Advanced Level) 1091. Acute Stroke (30)的更多相关文章
- 【PAT甲级】1091 Acute Stroke (30 分)(BFS)
题意: 输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小.输出一共有多少个单元满足所在联通块大小大于等于T. tr ...
- 1091. Acute Stroke (30)
题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...
- 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
题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...
- PAT (Advanced Level) 1111. Online Map (30)
预处理出最短路再进行暴力dfs求答案会比较好.直接dfs效率太低. #include<cstdio> #include<cstring> #include<cmath&g ...
- PAT (Advanced Level) 1107. Social Clusters (30)
简单并查集. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT (Advanced Level) 1103. Integer Factorization (30)
暴力搜索. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1072. Gas Station (30)
枚举一下选的位置,每次算一下就可以了. #include<cstdio> #include<cstring> #include<cmath> #include< ...
- PAT (Advanced Level) 1049. Counting Ones (30)
数位DP.dp[i][j]表示i位,最高位为j的情况下总共有多少1. #include<iostream> #include<cstring> #include<cmat ...
随机推荐
- MySQL安装--ubuntu
1. 执行命令: $ apt-get install mysql-server 执行上述命令会自动安装mysql-client,mysql-common等包. 2. 安装过程中会让你给root账号设置 ...
- python datetime时间差
import datetime import time d1 = datetime.datetime(2005, 2, 16) d2 = datetime.datetime(2004, 12, 31) ...
- css3 media媒体查询器用法总结 兼容ie8以下的方法
总结一下响应式设计的核心CSS技术Media(媒体查询器)的用法. http://www.360doc.com/content/14/0704/06/10734150_391862769.shtml ...
- CentOS7 PostgreSQL 安装
PostgreSQL安装 安装使用yum安装 (找源 http://yum.postgresql.org/) yum install https://download.postgresql.org/p ...
- Oracle where 0=1 or 1=1
本文转载自:http://www.cnblogs.com/junyuz/archive/2011/03/10/1979646.html sql where 1=1和 0=1 的作用 where 1 ...
- js连续赋值、指针
jq的源码中有很多连续赋值,类似这样的: var a = {n:1}; var b = a; // 持有a,以回查 a.x = a = {n:2}; alert(a.x);// --> unde ...
- tablehost
返回键的拦截 @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEven ...
- 免费 WebOffice使用
目前WebOffice使用比较多主要有两个公司的产品,分别是江西金格和北京点聚.但是点聚的是免费的,虽然有欠缺之处,但是经过个人修改还是比较好用的,关键一点是,它免费啊! 把一个最主要加载页面,如果读 ...
- Python定制类
https://docs.python.org/3/reference/datamodel.html#special-method-names
- robot framework -记录关键字
1.set value if (当条件满足时,进行变量赋值) 2.focus (将焦点定在制定的元素) 3.win close +title(关闭制定title) 4.get list items ...