PAT (Advanced Level) 1091. Acute Stroke (30)
2024-10-19 05:18:15
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 ;
}
最新文章
- Compute Resource Consolidation Pattern 计算资源整合模式
- HTML5中引入的关键特性
- Runtime 动态加载方法
- c#学习<;二>;:数据类型
- <;转>;VPN技术原理
- url.py中的配置问题
- 基于Extjs的web表单设计器 第四节——控件拖放
- [jQuery编程挑战]001:实现页面元素加速动画效果
- POJ1077&;&;HDU1043(八数码,IDA*+曼哈顿距离)
- DOCKER 从入门到放弃(三)
- 【tyvj P4868】天天和不可描述
- MySQL大小写敏感问题和命名规范
- python--使用队列结构来模拟烫手山芋的游戏
- Kubernetes调用vSphere vSAN做持久化存储
- Blender下各种坐标系
- 在shell 中字符串,文件,数字的比较
- ballerina 学习二十四 监控ballerina
- javac和java的使用
- 解决 sun.security.validator.ValidatorException: PKIX path building failed
- 【BZOJ4152】[AMPPZ2014]The Captain 最短路
热门文章
- 在Java 线程中返回值的用法
- hdu_4539_郑厂长系列故事——排兵布阵(状压DP|最大团)
- Chrome不支持showModalDialog模态对话框和无法返回returnValue的问题
- Bitmap和Drawable浅谈
- UnicodeEncodeError: &#39;ascii&#39; codec can&#39;t encode characters in position 14-15: ordinal not in range(128)
- apache启动报错:Cannot load php5apache2_2.dll into server
- 【dp】 poj 1157
- dsplay:table页面合并表格
- 实测switch支持的参数类型
- android上的JAVA8:使用retrolambda