1091. Acute Stroke (30)

#include <iostream>
#include <queue>

using namespace std;

struct node
{
	int x, y, z;
};

queue<node> q;
int flag[1300][130][70], m, n, l, vis[1300][130][70], bfscount;
int movenode[6][3] = 
{
	0, 0, 1,
	0, 0, -1,
	1, 0, 0,
	-1, 0, 0,
	0, -1, 0,
	0, 1, 0
};

node getnode(int x, int y, int z)
{
	node nod;
	nod.x = x;
	nod.y = y;
	nod.z = z;

	return nod;
}

void add(int x, int y, int z)
{
	if(x >= 0 && x < m && y >= 0 && y < n && z >= 0 && z < l && vis[x][y][z] == 0 && flag[x][y][z] == 1)
	{
		vis[x][y][z] = 1;
		q.push(getnode(x, y, z));
	}
}

void bfs()
{
	int qsize = q.size(), i;
	node cur;

	bfscount += qsize;

	while(qsize--)
	{
		cur = q.front();
		q.pop();

		for(i = 0; i < 6; i++)
		{
			add(cur.x + movenode[i][0], cur.y + movenode[i][1], cur.z + movenode[i][2]);
		}
	}

	qsize = q.size();
	if(qsize > 0)
	{
		bfs();
	}
}

int main()
{
	int t;
	scanf("%d%d%d%d", &m, &n, &l, &t);

	int i, j, k;
	for(k = 0; k < l; k++)
	{
		for(i = 0; i < m; i++)
		{
			for(j = 0; j < n; j++)
			{
				scanf("%d", &flag[i][j][k]);
			}
		}
	}

	int res = 0;
	for(k = 0; k < l; k++)
	{
		for(i = 0; i < m; i++)
		{
			for(j = 0; j < n; j++)
			{
				if(vis[i][j][k] == 0 && flag[i][j][k] == 1)
				{
					vis[i][j][k] = 1;
					bfscount = 0;

					q.push(getnode(i, j, k));
					bfs();

					if(bfscount >= t)
					{
						res += bfscount;
					}
				}
			}
		}
	}

	printf("%d\n", res);

	system("pause");
	return 0;
}

 

posted on 2025-11-23 17:21  王景迁  阅读(0)  评论(0)    收藏  举报

导航