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 ;
}

最新文章

  1. Compute Resource Consolidation Pattern 计算资源整合模式
  2. HTML5中引入的关键特性
  3. Runtime 动态加载方法
  4. c#学习&lt;二&gt;:数据类型
  5. &lt;转&gt;VPN技术原理
  6. url.py中的配置问题
  7. 基于Extjs的web表单设计器 第四节——控件拖放
  8. [jQuery编程挑战]001:实现页面元素加速动画效果
  9. POJ1077&amp;&amp;HDU1043(八数码,IDA*+曼哈顿距离)
  10. DOCKER 从入门到放弃(三)
  11. 【tyvj P4868】天天和不可描述
  12. MySQL大小写敏感问题和命名规范
  13. python--使用队列结构来模拟烫手山芋的游戏
  14. Kubernetes调用vSphere vSAN做持久化存储
  15. Blender下各种坐标系
  16. 在shell 中字符串,文件,数字的比较
  17. ballerina 学习二十四 监控ballerina
  18. javac和java的使用
  19. 解决 sun.security.validator.ValidatorException: PKIX path building failed
  20. 【BZOJ4152】[AMPPZ2014]The Captain 最短路

热门文章

  1. 在Java 线程中返回值的用法
  2. hdu_4539_郑厂长系列故事——排兵布阵(状压DP|最大团)
  3. Chrome不支持showModalDialog模态对话框和无法返回returnValue的问题
  4. Bitmap和Drawable浅谈
  5. UnicodeEncodeError: &#39;ascii&#39; codec can&#39;t encode characters in position 14-15: ordinal not in range(128)
  6. apache启动报错:Cannot load php5apache2_2.dll into server
  7. 【dp】 poj 1157
  8. dsplay:table页面合并表格
  9. 实测switch支持的参数类型
  10. android上的JAVA8:使用retrolambda