#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include <queue>
using namespace std;
int N=;
int ax[]={,,,-,,,-,-};
int ay[]={,-,,,-,,-,};
//bfs队列加对象,对象就是队列的类型,在这个题中就可以直接用x,y
//满足条件(为#)的对象插入队列
struct Point{
int x;
int y;
};
queue<Point> q;
//标记是否到达
int mark[][]={};
char data[][];
void bfs(int i,int j,int a,int b){
mark[i][j]=;
q.push({i,j});
N++;
while(!q.empty()){
Point first=q.front();
q.pop();
for (int k = ; k < ; ++k) {
int x=first.x+ax[k];
int y=first.y+ay[k];
if(x>= && x<a && y>= && y<b && data[x][y]=='@' && mark[x][y]==){
mark[x][y]=;
q.push({x,y});
} }
}
}
int main(){
int a,b;
while(cin>>a>>b) {
if(a== && b==){
break;
}
N=;
for (int i = ; i < a; ++i) {
for (int j = ; j < b; ++j) {
cin >> data[i][j]; } } for (int k = ; k < a; ++k) {
for (int l = ; l < b; ++l) {
//cout<<data[k][l]<<endl;
if (data[k][l] == '@' && mark[k][l]==) { bfs(k, l, a, b);
} } }
cout << N<<endl;
for (int i = ; i < a; ++i) {
for (int j = ; j < b; ++j) {
data[i][j]=; } } for (int m = ; m < ; ++m) {
for (int i = ; i < ; ++i) {
data[m][i]='';
mark[m][i]=; } } } }

最新文章

  1. 慕课网-Java入门第一季-6-10 练习题
  2. Maven学习(三)生命周期
  3. iOS摄像头和相册-UIImagePickerController常用操作
  4. 用jquery追加的元素不能触发treeview事件
  5. os.walk获取同级目录具有随机性
  6. JS判断RadioButtonList是否有选中项
  7. Play Apple(博弈)
  8. debian(wheezy) chrome beta 38.0.2x.xxx Shockwave Flash was crashed 该解决方案崩溃.
  9. Canvas 阴影效果
  10. PostgreSql问题:ERROR: column &quot;1&quot; does not exist
  11. winscp工具和xshell连接linux机器时切换到root账户
  12. Win7 VS2017 NASM编译FFMPEG(2018.12.22)
  13. myeclipse部署报错报空指针异常
  14. C#实现焦点变色
  15. python web框架介绍对比
  16. ORACLE问题定位基本方法
  17. php检测iis环境是否支持htaccess
  18. (转)CreateThread与_beginthread,内存泄漏为何因(原帖排版有些不好 ,所以我稍微整理下)
  19. LeetCode之Regular Expression Matching
  20. test_bdc

热门文章

  1. typeof、instanceof与constructor
  2. 2020-06-30 pol实现execl导入导出
  3. 手写SpringMVC框架(一)-------项目搭建
  4. Dubbo远程调用之公司内部提供的服务
  5. java语言基础(五)_Scanner类_Random类_ArrayList类
  6. 干!垃圾微软!发布我的Netcore跨平台UI框架 CPF
  7. Java实现 第十一届蓝桥杯——超级胶水(渴望有题目的大佬能给小编提供一下题目,讨论群:99979568)
  8. day45 数据库基础
  9. Oracle数据库期末总结
  10. redis源码学习之工作流程初探