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 ...
随机推荐
- 简单配置,让ES6脚本在浏览器里飞
如果你只是想学习ES6语法,找个地方练习下写法.不想看环境如何搭配,就想简单的学习,那有两种简单的方式. 1.在Chrome浏览器里直接F12调出控制台 2.在浏览器里跑引用ES6的HTML页面 ...
- telnet客户端程序
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types. ...
- 访问权限,public private protected
百度经验这篇文章很不错:https://jingyan.baidu.com/article/bad08e1e8e9a9b09c851219f.html
- mysql 5.7 ERROR 1054(42S22) Unknown column 'password' in ‘field list’ 报错
mysql 忘记密码 报错?ERROR 1054(42S22) Unknown column 'password' in ‘field list’原因:5.7版本下的mysql数据库下已经没有pass ...
- pyqt5-顶层窗口特定操作-图标和标题和不透明度
图标: setWindowIcon(QIcon("resource/header_icon.png")) 设置窗口图标 icon=QIcon(r'大象.png') ...
- new和delete动态分配和撤销内存
视频:C++引用及new和delete的使用 一.new用法 使用new运算符时必须已知数据类型,new运算符会向系统堆区申请足够的存储空间,如果申请成功,就返回该内存块的首地址,动态分配失败,则返回 ...
- Ubuntu18.04安装搜狗拼音输入法皮肤透明解决方法
解决方法: 去搜狗输入法官网下载一个新的皮肤,然后右键用“搜狗输入法”打开,就解决了!!!
- 使用TensorFlow遇到的若干问题
一.查看版本: 进入到Python的命令行状态后,可以在终端输入查询命令如下: import tensorflow tensorflow.__version__ 查询tensorflow安装路径为: ...
- mysql 修改文件记录:
增: insert t1(id, name) values(1, "alex"), (2, "wusir"), (3, "dabing" ...
- python 的基础 学习 12天,函数
1, *args 动态 参数,万能参数 *args就是接受实参对应的剩余的位置参数,并将其放在元组中.在定义函数时,*args代表的是聚合. def func(*args): print(ar ...