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 ...
随机推荐
- mb_detect_encoding() 运行sitemap.php 字符编码不能转换修改php.ini
1.phpinfo() 找php.ini位置 2.备份然后 php.ini文件中顶部添加extension=php_mbstring.dll Call to undefined function mb ...
- hdu_3709_Balanced Number(数位DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题意:给你一个区间,让你找平衡数的个数 题解:设dp[i][j][k]为前i位以第j位为支撑点的 ...
- restlet不能接受angular post过来的数据
修改header create: { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded'} }
- Hibernate创建SessionFactory实例
private static SessionFactory sessionFactory = null; static { Configuration configuration =new Con ...
- HttpCookie类
转自:http://www.cnblogs.com/kissdodog/archive/2013/01/08/2851937.html HttpCookie类专门由C#用于读取和写入Cookie的类. ...
- Object.setPrototypeOf 方法的使用
将一个指定的对象的原型设置为另一个对象或者null(既对象的[[Prototype]]内部属性). 语法 Object.setPrototypeOf(obj, prototype) 参数 obj 将被 ...
- CodeForces 566B Replicating Processes
#include <bits/stdc++.h> #define N 3010 #define LL long long #define unsigned U using namespac ...
- this的应用
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- CodeForces#378--A, B , D--暴力出奇迹....
A题 A. Grasshopper And the String time limit per test 1 second memory limit per test 256 megabytes in ...
- JS 的NULL undefined 空
null,对象不存在 var ii= document.getElementById("id"); alert(ii); 当前页面不存在id对象 undefined var i; ...