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)的更多相关文章

  1. 【PAT甲级】1091 Acute Stroke (30 分)(BFS)

    题意: 输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小.输出一共有多少个单元满足所在联通块大小大于等于T. tr ...

  2. 1091. Acute Stroke (30)

    题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...

  3. 1091 Acute Stroke (30)(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 (Advanced Level) 1111. Online Map (30)

    预处理出最短路再进行暴力dfs求答案会比较好.直接dfs效率太低. #include<cstdio> #include<cstring> #include<cmath&g ...

  6. PAT (Advanced Level) 1107. Social Clusters (30)

    简单并查集. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...

  7. PAT (Advanced Level) 1103. Integer Factorization (30)

    暴力搜索. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  8. PAT (Advanced Level) 1072. Gas Station (30)

    枚举一下选的位置,每次算一下就可以了. #include<cstdio> #include<cstring> #include<cmath> #include< ...

  9. PAT (Advanced Level) 1049. Counting Ones (30)

    数位DP.dp[i][j]表示i位,最高位为j的情况下总共有多少1. #include<iostream> #include<cstring> #include<cmat ...

随机推荐

  1. LeetCode OJ 220.Contains Duplicate 3

    Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...

  2. 【转】PHP android ios相互兼容的AES加密算法

    APP项目用户密码传输一直没有用HTTPS,考虑到用户的隐私暂时先用AES对密码加密,以后也可以用于手机端与服务端加密交互. PHP的免费版phpAES项目,手机端解码各种不对. 好不容易找了PHP ...

  3. Let'sencrypt认证的网站Https配置

    推荐使用这个脚本,具体说明里面都有 https://github.com/xdtianyu/scripts/tree/master/le-dns 它是通过调用dns服务商的api更新txt记录实现,无 ...

  4. weblogic 密码加密

    先启动域:

  5. byte数组与int,long,short,byte转换 (转载)

    byte数组和short数组转换 public short bytesToShort(byte[] bytes) { return ByteBuffer.wrap(bytes).order(ByteO ...

  6. 为什么要在onNewIntent的时候要显示的去调用setIntent

    一.原因: 当调用到onNewIntent(intent)的时候,需要在onNewIntent() 中使用setIntent(intent)赋值给Activity的Intent.否则,后续的getIn ...

  7. arcconf

    arcconf create 1 logicaldrive max volume 0 31 noprompt 创建 Logical Drive, 这里 0 31 就是之前记录的 Channel, De ...

  8. java 区分error和exception

    1) java.lang.Error: Throwable的子类,用于标记严重错误.合理的应用程序不应该去try/catch这种错误.绝大多数的错误都是非正常的,就根本不该出现的.java.lang. ...

  9. HDU 2844 Coins 背包问题 + 二进制优化

    题目大意:某个人有n种硬币,每种硬币价值为v,数量为c,问在总价值不超过m的条件下,最多有多少种组合方式. 题目思路: 1.对于某种硬币 如果v*c 大于 m,就意味着无论取多少枚硬币,只要总价值不大 ...

  10. UITableView使用中的一些刁专问题总结

    tableview中cell的系统分隔线问题(分隔线顶满或者缩短) //tableview代理方法,设置系统cell的分隔线 -(void)tableView:(UITableView *)table ...