1091 Acute Stroke (30 分)

1091 Acute Stroke (30 分)

解题思想

AC代码

#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int m, n, l, t;
int arr[1300][130][80];
bool visit[1300][130][80];
int X[6] = {1, 0, 0, -1, 0, 0};
int Y[6] = {0, 1, 0, 0, -1, 0};
int Z[6] = {0, 0, 1, 0, 0, -1};
struct node{
    int x, y, z;
};
bool judge(int x, int y, int z){
    if (x<0||x>=m||y<0||y>=n||z<0||z>=l) return false;
    if (arr[x][y][z] == 0 || visit[x][y][z] == true) return false;
    return true;
}
int bfs(int x, int y, int z){
    int cnt = 0;
    node tmp;
    tmp.x = x;
    tmp.y = y;
    tmp.z = z;
    queue<node> q;
    q.push(tmp);
    visit[x][y][z] = true;
    while (!q.empty()){
        node top = q.front();
        q.pop();
        cnt++;
        for (int i = 0; i < 6; i++){
            int tx = top.x + X[i];
            int ty = top.y + Y[i];
            int tz = top.z + Z[i];
            if (judge(tx, ty, tz)){
                visit[tx][ty][tz] = true;
                tmp.x = tx;
                tmp.y = ty;
                tmp.z = tz;
                q.push(tmp);
            }
        }
    }
    if (cnt >= t) return cnt;
    else return 0;
}
int main(){
    scanf("%d%d%d%d", &m, &n, &l, &t);
    for (int i = 0; i < l; i++)
        for (int j = 0; j < m; j++)
            for (int k = 0; k < n; k++)
                scanf("%d", &arr[j][k][i]);
    int ans = 0;
    for (int i = 0; i < l; i++)
        for (int j = 0; j < m; j++)
            for (int k = 0; k < n; k++)
                if (arr[j][k][i] == 1 && visit[j][k][i] == false)
                    ans += bfs(j, k, i);
    printf("%d", ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值