https://pintia.cn/problem-sets/994805046380707840/exam/problems/994805052626026496
输入样例:
3 4 5 2
1 1 1 1
1 1 1 1
1 1 1 1
0 0 1 1
0 0 1 1
0 0 1 1
1 0 1 1
0 1 0 0
0 0 0 0
1 0 1 1
0 0 0 0
0 0 0 0
0 0 0 1
0 0 0 1
1 0 0 0
输出样例:
26
LL dz[]={1,-1,0,0,0,0},dx[]={0,0,1,-1,0,0},dy[]={0,0,0,0,1,-1};
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e6+10,M=2023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL m,n,l,t;
LL a[65][1500][150];
struct Point
{
int x,y,z;
};
LL sum=0,ans=0;
LL dz[]={1,-1,0,0,0,0},dx[]={0,0,1,-1,0,0},dy[]={0,0,0,0,1,-1};
int bfs(LL ll,LL mm,LL nn)
{
queue<Point> q;
q.push({ll,mm,nn});
a[ll][mm][nn]=0;
sum++;
while(q.size())
{
auto t=q.front();
q.pop();
for(LL i=0;i<6;i++)
{
LL zz=dz[i]+t.x,xx=dx[i]+t.y,yy=dy[i]+t.z;
if(zz>=1&&zz<=l&&xx>=1&&xx<=m&&yy>=1&&yy<=n&&a[zz][xx][yy]==1)
{
q.push({zz,xx,yy});
a[zz][xx][yy]=0;
sum++;
}
}
}
return sum;
}
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
cin>>m>>n>>l>>t;
for(int i=1;i<=l;i++)
{
for(int j=1;j<=m;j++)
{
for(int k=1;k<=n;k++)
{
cin>>a[i][j][k];
}
}
}
for(int i=1;i<=l;i++)
{
for(int j=1;j<=m;j++)
{
for(int k=1;k<=n;k++)
{
if(a[i][j][k]==1)
{
sum=0;
bfs(i,j,k);
if(sum>=t) ans+=sum;
}
}
}
}
cout<<ans<<endl;
}
return 0;
}
标签:练习题,const,nn,int,LL,bfs,L3,&&
From: https://www.cnblogs.com/Vivian-0918/p/17304243.html