题意
找三维图中的连通块的面积,即1的个数 连通块有个要求如果小于给定的范围就不计!
思路
开始时用dfs做,栈溢出了。。。数据大了!
换成bfs寻找连通即可!
存图是zxy,而计算按照xyz了!!!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int mp[60+2][1286+2][128+2];
int ans;
struct unt {
int x,y,z;
};
int dx[]= {1,-1,0,0,0,0},dy[]= {0,0,1,-1,0,0},dz[]= {0,0,0,0,-1,1};
int t,m,n,l;
bool check(unt a) {
if(a.x>=0 && a.x<n && a.y>=0 && a.y<m && a.z>=0 && a.z<l && mp[a.z][a.x][a.y] == 1) return 1;
return 0;
}
void bfs(int x,int y,int z) {
unt cur= {x,y,z},next;
queue<unt>q;
q.push(cur);
int cnt = 1;
mp[z][x][y] = 0;
while(!q.empty()) {
cur = q.front();
q.pop();
for(int i=0; i<6; i++) {
next.x = cur.x+dx[i];
next.y = cur.y+dy[i];
next.z = cur.z+dz[i];
if(check(next)) {
mp[next.z][next.x][next.y]