#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
string w[30];
int xingzou[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
struct p
{
int x,y;
};
queue<p> q;
int main()
{
int T;
cin>>T;
int u=0;
while(T--)
{
int n,m;
cin>>n>>m;
for(int a=0;a<m;a++)cin>>w[a];
int x,y;
for(int a=0;a<m;a++)
{
// cout << w[a] << endl;
for(int b=0;b<n;b++)
{
if(w[a][b]=='@')
{
x=a;
y=b;
}
}
}
int jishu=0;
p e={x,y};
q.push(e);
w[x][y]='#';
// int www=q.size();
while(!q.empty())
{
p eee=q.front();
q.pop();
// www=q.size();
// w[eee.x][eee.y]='#';
jishu++;
// cout << jishu << endl;
for(int a=0;a<4;a++)
{
int qq=eee.x+xingzou[a][0];
int ww=eee.y+xingzou[a][1];
// cout << qq << " " << ww << endl;
// cout << w[qq][ww] << endl;
// cout << n << m << endl;
// puts("mm");
if(qq>=0&&ww>=0&&qq<m&&ww<n&&w[qq][ww]=='.')
{
p qqq={qq,ww};
q.push(qqq);
w[qq][ww]='#';
// www=q.size();
}
}
}
printf("Case %d: %d\n",++u,jishu);
}
return 0;
}
lightoj 1012 水广搜。。。最近我脑子不大好了
最新推荐文章于 2019-07-24 08:32:09 发布