//
// main.cpp
// dfs-bfs搜索
//
// Created by liuzhe on 16/8/10.
// Copyright © 2016年 my_code. All rights reserved.
//
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int w,h;
int n;
char z[21][21];
int dfs(int i,int j)
{
if(i<1||j<1||i>h||j>w)
return 0;
if(z[i][j]!='#')
{
z[i][j]='#';
return 1+dfs(i-1,j)+dfs(i+1,j)+dfs(i,j-1)+dfs(i,j+1);
}
else
return 0;
}
int main(int argc, const char * argv[]) {
// insert code here...
cin>>n;
for(int k=1;k<=n;++k)
{
cin>>w>>h;
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++)
cin>>z[i][j];
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++)
if(z[i][j]=='@')
cout<<"Case "<<k<<": "<<dfs(i,j)<<endl;
}
//std::cout << "Hello, World!\n";
return 0;
}
LightOJ 1012
最新推荐文章于 2019-07-24 08:32:09 发布