码迷,mamicode.com
首页 > 其他好文 > 详细

1091 acute stroke

时间:2016-03-10 23:22:09      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

三维空间的DFS,挺新颖的一题

AC代码:

#include <vector>
#include <cstdio>
#include <queue>
using namespace std;
int x[] = {0,0,1,0,-1,0};
int y[] = {0,1,0,-1,0,0};
int z[] = {-1,0,0,0,0,1};
class node{
public:
    int x;
    int y;
    int z;
    node(int xx,int yy,int zz):x(xx),y(yy),z(zz){}
    node(){}
};
int main(){
    int n,m,l,t;
    scanf("%d %d %d %d",&n,&m,&l,&t);
    vector<vector<vector<int>>> cub;
    vector<vector<vector<bool>>> vs;
    for(int i = 0;i < l;i++){
        vector<vector<int>> p;
        vector<vector<bool>> pvs;
        for(int j = 0;j < n;j++){
            vector<int> line;
            vector<bool> vline;
            for(int k = 0;k < m;k++){
                int tmp;
                scanf("%d",&tmp);
                line.push_back(tmp);
                vline.push_back(false);
            }
            p.push_back(line);
            pvs.push_back(vline);
        }
        cub.push_back(p);
        vs.push_back(pvs);
    }
    int num(0);
    for(int i = 0;i < l;i++){
        for(int j = 0;j < n;j++){
            for(int k = 0;k < m;k++){
                if(vs[i][j][k] || cub[i][j][k] == 0)
                    continue;
                else{
                    queue<node> q;
                    node tmp(j,k,i);
                    q.push(tmp);
                    vs[i][j][k] = true;
                    int count(1);
                    while(!q.empty()){
                        for(int s = 0;s < 6;s++){
                            node son(q.front().x + x[s],q.front().y + y[s],q.front().z + z[s]);
                            if(son.z >= 0 && son.z < l && son.x >= 0 && son.x < n && son.y >= 0 && son.y < m && !vs[son.z][son.x][son.y]
                                && cub[son.z][son.x][son.y] == 1){
                                vs[son.z][son.x][son.y] = true;
                                q.push(son);
                                count++;
                            }
                        }
                        q.pop();
                    }
                    if(count >= t)
                        num += count;
                }
            }
        }
    }
    printf("%d\n",num);
    return 0;
}

 

1091 acute stroke

标签:

原文地址:http://www.cnblogs.com/Aldorado/p/5263903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!