poj1562 Oil Deposits 深搜模板题
题目描述:
Description
Input
Output
Sample Input
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
Sample Output
0
1
2
2 题意:
判断在一个图形中‘@’连通的有几块。 题解:
典型的dfs模板题,套用模板即可。并记得将搜索过的’@‘转换成’*‘ 代码:
#include <iostream>
#include <stdio.h>
#include <string.h> using namespace std;
char a[][];
int n,m,i,j; void dfs(int x,int y)
{
a[x][y]='*';
for(int dx=-;dx<=;dx++) //以一个点为中心,判断他周围有无‘@’,一直搜索下去,直到没有相连通的‘@’
for(int dy=-;dy<=;dy++){
int nx=dx+x;
int ny=dy+y;
if(nx>=&&nx<n&&ny>=&&ny<m&&a[nx][ny]=='@') dfs(nx,ny);
}
return ;
} void solve()
{
int ans=;
for(i=;i<n;i++)
for(j=;j<m;j++){
if(a[i][j]=='@')
{
dfs(i,j);
ans++; //每遇到一个‘@’,就将连通快总数加1,并通过dfs把相连通的‘@’都转化成‘*’
}
}
printf("%d\n",ans);
} int main()
{
while(){
scanf("%d%d",&n,&m);
if(n==&&m==) break;
memset(a,,sizeof(a));
for(i=;i<n;i++){
scanf("%s",a[i]); //输入的时候要注意,如果输入%c,记得加getchar();
}
solve();
}
return ;
}
poj1562 Oil Deposits 深搜模板题的更多相关文章
- poj1562 Oil Deposits(DFS)
题目链接 http://poj.org/problem?id=1562 题意 输入一个m行n列的棋盘,棋盘上每个位置为'*'或者'@',求'@'的连通块有几个(连通为8连通,即上下左右,两条对角线). ...
- nyoj20——有向无环图深搜模板
吝啬的国度 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来.现在,Tom在第S号城市, ...
- uva12558 Egyptian Fractions (HARD version)(迭代深搜)
Egyptian Fractions (HARD version) 题解:迭代深搜模板题,因为最小个数,以此为乐观估价函数来迭代深搜,就可以了. #include<cstdio> #inc ...
- POJ 1562:Oil Deposits
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14462 Accepted: 7875 Des ...
- [vijos1159&洛谷1494]岳麓山上打水<迭代深搜>
题目链接:https://vijos.org/p/1159 https://www.luogu.org/problem/show?pid=1494 这是今天的第三道迭代深搜的题,虽然都是迭代深搜的模板 ...
- NYoj 素数环(深搜入门)
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=488 深搜模板: void dfs(int 当前状态) { if(当前状态为边界状 ...
- (深搜)Oil Deposits -- hdu -- 1241
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU_1241 Oil Deposits(DFS深搜)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
- 暑假集训(1)第七弹 -----Oil Deposits(Poj1562)
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
随机推荐
- 【八】Spring Cloud Config
一.分布式系统面临的--配置问题 微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的力度相对较小,因此系统中会出现大量的服务.由于每个服务都需要必要的配置信息才能运行,所以一套集中式的.动 ...
- ASP.NET Web API 2 使用 DelegatingHandler(委托处理程序)实现签名认证
Ø 前言 在前一篇ASP.NET Web API 2 使用 AuthorizationFilter(授权过滤器)实现 Basic 认证文章中实现了采用 Basic 认证的方式,但是这种方式存在安全隐 ...
- 检查CentOS7定时任务是否启用并执行过
1 监控cron状态 service crontab status #如果没有开启执行 service crontab start 正常开启的状态 2 检查执行日志,过滤自己配置的定时任务脚本关键字 ...
- git 重命名 origin
git remote rename origin old-origin git remote add origin https://gitlab.com/wuxianqiang/my-project. ...
- mysql常用命令及语法规范
mysql命令不区分大小写,函数和关键字建议使用大写字母,以分号结束语句. 显示当前服务器版本 SELECT VERSION(); 显示当前时间 SELECT NOW(); 显示当前用户 SELECT ...
- jmeter(五)几种不同的content-type方式
今天我们来讲3种常见的content-type方式,及jmeter应用时信息头和传参方式的不同: 参照博客http://www.cnblogs.com/imyalost/p/6726795.html ...
- JAVA进阶1
间歇性混吃等死,持续性踌躇满志系列-------------第1天 1.冒泡排序法 import java.util.Arrays; public class SumNum{ public stati ...
- 存在Settings数据在手机系统中的位置
旧版本Android,将settings数据存在数据库中,{system, secure, global} 对应的是 /data/data/com.android.providers.settings ...
- python基本数据结构栈stack和队列queue
1,栈,后进先出,多用于反转 Python里面实现栈,就是把list包装成一个类,再添加一些方法作为栈的基本操作. 栈的实现: class Stack(object): #初始化栈为空列表 def _ ...
- golang interface 转 string,int,float64
func interface2String(inter interface{}) { switch inter.(type) { case string: fmt.Println("stri ...