UVA - 572 Oil Deposits(dfs)
2024-10-12 00:44:06
题意:求连通块个数。
分析: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);
}
}
最新文章
- linux如何修改文件或目录的权限(chmod)
- linux 防火墙设置
- PHP文件系统处理相关操作
- C#string常用函数总结
- dshow,Sample Grabber 从摄像头采集
- PHP CURL访问HTTPS使用详解
- 【POJ11855】 Buzzwords (后缀数组)
- springmvc对jsonp的支持
- NG2入门 - 根模块
- 类似818tu.co微信小说分销系统设计之多公众号网页授权自动登录源码
- springBoot系列教程04:mybatis及druid数据源的集成及查询缓存的使用
- JEECG中的模糊查询
- sed从入门到深入的使用心得
- 【转载】许纪霖教授在上海财经大学演讲——漫谈“大学生的四个Learn”
- Alpha冲刺(8/10)
- Brocade SAN交换机常用命令
- sqlplus连接远程数据库
- HTML5 data属性
- java基础-day28
- sql server中QUOTENAME()函数的用法
热门文章
- MYSQL- 存储过程示例
- 前端 - 使用gulp搭建es6运行环境
- cas 3.5.2 登录成功后,如何返回用户更多信息?
- iOS stretchableImageWithLeftCapWidth 图片放大不变形
- 上struts2的xml在&;lt;result type=&;quot;redirect&;quot;&;gt;参数问题
- (原)nginx 源码编译
- C#_dropdownlist_3
- 解读eXtremeComponents代码结构--转载
- Preparing for Different Databases
- Android(java)学习笔记131:Intent启动别的Activity