#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;
}
}
采蘑菇
最新推荐文章于 2021-09-11 18:56:17 发布