题目大意:
看了别人博客我才搞懂题目意思.....PAT这题目意思也太那啥了,,,,感觉最难的部分就是读懂题目意思了.
bfs解法,很传统老套的做法,就是三维块中,如果一个连通块其大小不小于k那么就记录答案数.给定三维状态图.
#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define ull unsigned long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)#define base 2333
const int mod=1e9+7;
const int maxn=1e5+10;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){if(y==0) return x;return gcd(y,x%y);
}
int flag[70][1300][130];
int m,n,l,t,ans=0;
bool judge(int x,int y,int z){if(x<0||x>=l) return false;if(y<0||y>=m) return false;if(z<0||z>=n) return false;if(!flag[x][y][z]) return false;return true;
}
int dir1[]={0,0,0,0,1,-1};
int dir2[]={0,0,1,-1,0,0};
int dir3[]={1,-1,0,0,0,0};
int bfs(int x,int y,int z){int ret=0;queue<piii> q;q.push(mk(x,mk(y,z)));while(!q.empty()){piii tp=q.front();q.pop();int tx=tp.fi,ty=tp.se.fi,tz=tp.se.se;if(!flag[tx][ty][tz]) continue;///注意点flag[tx][ty][tz]=0,ret++;rep(i,0,6){if(!judge(tx+dir1[i],ty+dir2[i],tz+dir3[i])) continue;q.push(mk(tx+dir1[i],mk(ty+dir2[i],tz+dir3[i])));}}return ret;
}
int main(){ios::sync_with_stdio(false);cin>>m>>n>>l>>t;rep(i,0,l) rep(j,0,m) rep(k,0,n) cin>>flag[i][j][k];rep(i,0,l) rep(j,0,m) rep(k,0,n) if(flag[i][j][k]){int cnt=bfs(i,j,k);ans+=(cnt>=t?cnt:0);}cout<<ans<<"\n";return 0;
}