标签:can oid 整数 方法 模板 [] clu 一个 code
#include <bits/stdc++.h> #define ll long long using namespace std; int num[55][55][55]; bool mp[55][55][55]; int d; int n,m,h; int dx[]={0,0,-1,1,0,0}; int dy[]={1,-1,0,0,0,0}; int dz[]={0,0,0,0,1,-1}; bool check(int x,int y,int z) { if(x<1||x>n||y<1||y>m||z<1||z>h) return 1; if(mp[x][y][z]) return 1; return 0; } void dfs(int x,int y,int z,int p){ mp[x][y][z]=true; for(int i=0; i<6; ++i){ int next_x=x+dx[i]; int next_y=y+dy[i]; int next_z=z+dz[i]; if(next_x>=1&&next_x<=n&&next_y>=1&&next_y<=m&&next_z>=1&&next_z<=h&&!mp[next_x][next_y][next_z]&&abs(num[next_x][next_y][next_z]-p)<=d) { dfs(next_x,next_y,next_z,num[next_x][next_y][next_z]); } } } int main(){ scanf("%d%d%d%d",&n,&m,&h,&d); for(int i=1;i<=n;++i){ for(int j=1;j<=m;++j){ for(int k=1;k<=h;++k){ scanf("%d",&num[i][j][k]); } } } int ent=0; for(int i=1;i<=n;++i){ for(int j=1;j<=m;++j){ for(int k=1;k<=h;++k){ if(!mp[i][j][k]){ ent++; dfs(i,j,k,num[i][j][k]); } } } } printf("%d\n",ent); return 0; }
标签:can oid 整数 方法 模板 [] clu 一个 code
原文地址:https://www.cnblogs.com/Diliiiii/p/10305774.html