标签:nod type space tmp c++ sof include node ios
#include<bits/stdc++.h>
using namespace std;
int n,m,l,t;
int a[1307][137][67];
int vis[1307][137][67];
typedef struct{
int x,y,z;
}node;
int xx[6]={0,0,0,0,1,-1};
int yy[6]={0,0,1,-1,0,0};
int zz[6]={1,-1,0,0,0,0};
node p;
int bfs(int x,int y,int z){
queue<node>q;
vis[x][y][z]=1;
p.x=x;
p.y=y;
p.z=z;
q.push(p);
int sum=0;
while(!q.empty()){
node tmp=q.front();
q.pop();
sum++;
for(int i=0;i<6;++i){
int tx=tmp.x+xx[i];
int ty=tmp.y+yy[i];
int tz=tmp.z+zz[i];
if(tx>0&&tx<=n&&ty>0&&ty<=m&&tz>0&&tz<=l&&a[tx][ty][tz]&&!vis[tx][ty][tz]){
p.x=tx;
p.y=ty;
p.z=tz;
q.push(p);
vis[tx][ty][tz]=1;
}
}
}
if(sum>=t)
return sum;
return 0;
}
int main(){
std::ios::sync_with_stdio(false);
cin>>n>>m>>l>>t;
for(int i=1;i<=l;++i)
for(int j=1;j<=n;++j)
for(int k=1;k<=m;++k)
cin>>a[j][k][i];
int ans=0;
for(int i=1;i<=l;++i)
for(int j=1;j<=n;++j)
for(int k=1;k<=m;++k)
if(a[j][k][i]&&!vis[j][k][i])
ans+=bfs(j,k,i);
cout<<ans;
return 0;
}
The Largest Generation (25)(BFS)(PAT甲级)
标签:nod type space tmp c++ sof include node ios
原文地址:https://www.cnblogs.com/ldudxy/p/10841620.html