zoukankan      html  css  js  c++  java
  • A1091 Acute Stroke[bfs]

    在这里插入图片描述

    #include<iostream>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<string>
    #include<math.h>
    #include<algorithm>
    #include<map>
    #include<cstring>
    #include<set>
    using namespace std;
    struct node
    {
    	int x, y, z;
    }Node;
    int n, m, slice, T;
    int pixel[1290][130][61];
    bool inq[1290][130][61];
    int X[6] = { 0,0,0,0,1,-1 };
    int Y[6] = { 0,0,1,-1,0,0 };
    int Z[6] = { 1,-1,0,0,0,0 };
    
    bool judge(int x, int y, int z)
    {
    	if (pixel[x][y][z] == 0 || inq[x][y][z] == true)
    		return false;
    	return true;
    }
    
    int bfs(int x, int y, int z)
    {
    	int tot = 0;
    	queue<node>q;
    	Node.x = x, Node.y = y, Node.z = z;
    	q.push(Node);
    	inq[x][y][z] = true;
    	while (!q.empty())
    	{
    		node top = q.front();
    		q.pop();
    		tot++;
    		for (int i = 0; i < 6; i++)
    		{
    			int newx = top.x + X[i];
    			int newy = top.y + Y[i];
    			int newz = top.z + Z[i];
    			if (judge(newx, newy, newz))
    			{
    				Node.x = newx, Node.y = newy, Node.z = newz;
    				q.push(Node);
    				inq[newx][newy][newz] = true;
    			}
    		}
    	}
    	if (tot >= T) return tot;
    	else return 0;
    }
    
    int main()
    {
    	cin >> n >> m >> slice >> T;
    	for (int z = 0; z < slice; z++)
    		for (int x = 0; x < n; x++)
    			for(int y=0;y<m;y++)
    			{
    				cin >> pixel[x][y][z];
    			}
    				
    			
    	int ans = 0;
    	for (int z = 0; z < slice; z++)
    		for (int x = 0; x < n; x++)
    			for (int y = 0; y < m; y++)
    			{
    				if (judge(x,y,z))
    					ans += bfs(x, y, z);
    			}
    	cout << ans << endl;
    	return 0;
    }
    
  • 相关阅读:
    flask读书笔记-flask web开发
    flask 杂记
    ubuntu redis 安装 &基本命令
    redis 订阅&发布(转载)
    Redis键值设计(转载)
    python2 python3区别
    捕获异常
    开源的微信个人号接口
    工具
    HDU2966 In case of failure(浅谈k-d tree)
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13811983.html
Copyright © 2011-2022 走看看