• 【PAT甲级】1091 Acute Stroke (30 分)(BFS)


    题意:

    输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小。输出一共有多少个单元满足所在联通块大小大于等于T。

    trick:

    三元数组大小开小了。。。最后两个测试点答案错误,我是笨比。

    AAAAAccepted code:

     1 #define HAVE_STRUCT_TIMESPEC
     2 #include<bits/stdc++.h>
     3 using namespace std;
     4 int m,n,l,t;
     5 int a[67][1300][130];
     6 int vis[67][1300][130];
     7 int ans[67][1300][130];
     8 int xx[7]={0,1,0,0,-1,0,0};
     9 int yy[7]={0,0,1,0,0,-1,0};
    10 int zz[7]={0,0,0,1,0,0,-1};
    11 typedef struct nod{
    12     int x,y,z;
    13 };
    14 queue<nod>q;
    15 void dfs(int x,int y,int z){
    16     while(!q.empty()){
    17         ++ans[x][y][z];
    18         nod now=q.front();
    19         q.pop();
    20         for(int i=1;i<=6;++i){
    21             int tx=now.x+xx[i];
    22             int ty=now.y+yy[i];
    23             int tz=now.z+zz[i];
    24             if(!vis[tx][ty][tz]&&a[tx][ty][tz]==1){
    25                 nod node;
    26                 node.x=tx;
    27                 node.y=ty;
    28                 node.z=tz;
    29                 vis[tx][ty][tz]=1;
    30                 q.push(node);
    31             }
    32         }
    33     }
    34 }
    35 void clear(queue<nod>&q){
    36     queue<nod>emp;
    37     swap(q,emp);
    38 }
    39 int main(){
    40     ios::sync_with_stdio(false);
    41     cin.tie(NULL);
    42     cout.tie(NULL);
    43     cin>>m>>n>>l>>t;
    44     for(int i=1;i<=l;++i)
    45         for(int j=1;j<=m;++j)
    46             for(int k=1;k<=n;++k)
    47                 cin>>a[i][j][k];
    48     int sum=0;
    49     for(int i=1;i<=l;++i)
    50         for(int j=1;j<=m;++j)
    51             for(int k=1;k<=n;++k)
    52                 if(a[i][j][k]==1&&!vis[i][j][k]){
    53                     clear(q);
    54                     nod tamp;
    55                     tamp.x=i;
    56                     tamp.y=j;
    57                     tamp.z=k;
    58                     q.push(tamp);
    59                     vis[i][j][k]=1;
    60                     dfs(i,j,k);
    61                     if(ans[i][j][k]>=t)
    62                         sum+=ans[i][j][k];
    63                 }
    64     cout<<sum;
    65     return 0;
    66 }
    保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
  • 相关阅读:
    Python的一些版本分析
    2006年的长春.NET俱乐部
    大病了一场,不过闲时对AJAX探索时,实现了IE TREE无刷新
    关于AJAX开发
    提供可在WSS上使用的MYTREE
    关于WSS搜索的问题
    转发:使用JavaScript删除ASP.NET生成的HttpCookie
    AJAX(2)
    在将WEBPART打包成*.CAB包和*.MSI安装包后,竟然无法将其安装到指定的WSS网站
    转发:Session研习笔记
  • 原文地址:https://www.cnblogs.com/ldudxy/p/11907032.html
Copyright © 2020-2023  润新知