题意:求连通块个数。

分析:dfs。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, , -, -, , };
const int dc[] = {-, , , , -, , -, };
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
int cnt;
int m, n;
int vis[MAXN][MAXN];
char a[MAXN][MAXN];
int judge(int i, int j){
return i >= && i < m && j >= && j < n;
}
void dfs(int x, int y){
vis[x][y] = ;
for(int i = ; i < ; ++i){
int tmpx = x + dr[i];
int tmpy = y + dc[i];
if(judge(tmpx, tmpy) && !vis[tmpx][tmpy] && a[tmpx][tmpy] == '@'){
dfs(tmpx, tmpy);
}
}
}
int main(){
while(scanf("%d%d", &m, &n) == ){
if(!m && !n) return ;
memset(vis, , sizeof vis);
cnt = ;
for(int i = ; i < m; ++i)
scanf("%s", a[i]);
for(int i = ; i < m; ++i){
for(int j = ; j < n; ++j){
if(a[i][j] == '@' && !vis[i][j]){
++cnt;
dfs(i, j);
}
}
}
printf("%d\n", cnt);
}
}

最新文章

  1. linux如何修改文件或目录的权限(chmod)
  2. linux 防火墙设置
  3. PHP文件系统处理相关操作
  4. C#string常用函数总结
  5. dshow,Sample Grabber 从摄像头采集
  6. PHP CURL访问HTTPS使用详解
  7. 【POJ11855】 Buzzwords (后缀数组)
  8. springmvc对jsonp的支持
  9. NG2入门 - 根模块
  10. 类似818tu.co微信小说分销系统设计之多公众号网页授权自动登录源码
  11. springBoot系列教程04:mybatis及druid数据源的集成及查询缓存的使用
  12. JEECG中的模糊查询
  13. sed从入门到深入的使用心得
  14. 【转载】许纪霖教授在上海财经大学演讲——漫谈“大学生的四个Learn”
  15. Alpha冲刺(8/10)
  16. Brocade SAN交换机常用命令
  17. sqlplus连接远程数据库
  18. HTML5 data属性
  19. java基础-day28
  20. sql server中QUOTENAME()函数的用法

热门文章

  1. MYSQL- 存储过程示例
  2. 前端 - 使用gulp搭建es6运行环境
  3. cas 3.5.2 登录成功后,如何返回用户更多信息?
  4. iOS stretchableImageWithLeftCapWidth 图片放大不变形
  5. 上struts2的xml在&amp;lt;result type=&amp;quot;redirect&amp;quot;&amp;gt;参数问题
  6. (原)nginx 源码编译
  7. C#_dropdownlist_3
  8. 解读eXtremeComponents代码结构--转载
  9. Preparing for Different Databases
  10. Android(java)学习笔记131:Intent启动别的Activity