采蘑菇


#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
queue <pair<int,int> > q;
int map[105][105];
int visit[105][105];
int n,m,t;
int ans;
int ans1;
int dir[4][2]={-1,0,0,-1,1,0,0,1};
void  bfs(int a,int b){
    memset(visit,0,sizeof(visit));
    visit[a][b]=1;
    while(!q.empty())
       q.pop();
    q.push(make_pair(a,b));
    int hp=0,tp=1,lc=1;
    while(!q.empty()){
        hp++;
        pair<int,int> tmp;
        tmp=q.front();
        q.pop();
        //c//out<<tmp.first<<tmp.second<<endl;
        if(map[tmp.first][tmp.second]==1)
           ans++;
         //cout<<ans<<endl;
         for(int i=0;i<4;i++){
         int ii=tmp.first+dir[i][1];
         int jj=tmp.second+dir[i][0];
         if(ii>=0&&jj>=0&&ii<n&&jj<m&&!visit[ii][jj]&&map[ii][jj]!=2){
             visit[ii][jj]=1;
             //cout<<ii<<"jkj"<<jj<<endl;
             q.push(make_pair(ii,jj));
             tp++;
         }
        }
        if(hp==lc)
       {
           ans1++;
           lc=tp;
       }//如何按层记录
       //cout<<ans1<<endl;
       if(ans1==(t/2))
        break ;


    }

}
int main(){
    int ca=1;
    while(cin>>n>>m>>t){
        printf("Case %d:\n",ca++);
        ans=0;
        ans1=-1;
        for(int i=0;i<n;i++)
          for(int j=0;j<m;j++)
            cin>>map[i][j];
         for(int i=0;i<n;i++)
          for(int j=0;j<m;j++)
             if(map[i][j]==3)
               bfs(i,j);
          cout<<ans<<endl;
    }




}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值