题意:
输出和' @ '相连有多少个' . '包括' @ ',' # '代表墙不能走;
思路:
基础DFS,找到起点,然后跑一下DFS就好了;
#include<cstdio>
#include<queue>
#include<map>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL mod=1e9+7;
const int N=50;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
char ma[N][N];
int ans;
int n,m;
void dfs(int x,int y)
{
for(int i=0;i<4;i++)
{
int xx=x+dx[i];
int yy=y+dy[i];
if(xx<0||yy<0||xx>=n||yy>=m||ma[xx][yy]=='#')
continue;
ma[xx][yy]='#';
ans++;
dfs(xx,yy);
}
}
int main()
{
int T;
int cas=1;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&m,&n);
for(int i=0;i<n;i++)
scanf("%s",ma[i]);
int flag=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(ma[i][j]=='@')
{
ans=1;
ma[i][j]='#';
dfs(i,j);
flag=1;
}
if(flag)
break;
}
if(flag)
break;
}
printf("Case %d: %d\n",cas++,ans);
}
return 0;
}