UVa572 - Oil Deposits
解题思路:好久没写搜索了,练练手,陶冶情操。不多说,直接贴代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = ;
int dir[][] = {-, -, -, , -, , , -,
, , , -, , , , };
char gg[maxn][maxn];
int m, n; void DFS(int x, int y, int id)
{
if(x < || x > m || y < || y > n || gg[x][y] == '*') return ;
gg[x][y] = '*';
for(int i = ; i < ; i++)
{
int xx = x + dir[i][];
int yy = y + dir[i][]; if(xx < || xx > m || yy < || yy > n || gg[xx][yy] == '*') continue;
DFS(xx, yy, id);
}
return ;
}
int main()
{
int cnt;
while(~scanf("%d %d", &m, &n) && m)
{
memset(gg, '#', sizeof(gg));
for(int i = ; i <= m; i++)
for(int j = ; j <= n; j++) scanf(" %c", &gg[i][j]); cnt = ;
for(int i = ; i <= m; i++)
for(int j = ; j <= n; j++)
if(gg[i][j] == '@') DFS(i, j, ++cnt);
printf("%d\n", cnt);
}
return ;
}
UVa572 - Oil Deposits的更多相关文章
- UVa572 Oil Deposits DFS求连通块
技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...
- UVA572 Oil Deposits DFS求解
小白书上经典DFS题目. 1. 递归实现 // from: https://www.cnblogs.com/huaszjh/p/4686092.html #include <stdio.h> ...
- [C++]油田(Oil Deposits)-用DFS求连通块
[本博文非博主原创,均摘自:刘汝佳<算法竞赛入门经典>(第2版) 6.4 图] [程序代码根据书中思路,非独立实现] 例题6-12 油田(Oil Deposits,UVa572) 输入一个 ...
- Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Oil Deposits(dfs)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 2016HUAS暑假集训训练题 G - Oil Deposits
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- uva 572 oil deposits——yhx
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil d ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- hdu1241 Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- Office 2013 note
1.每次打开重新配置: 问题表现:启动后发现每次打开都会出现“正在配置”的进度 执行:reg add HKCU\Software\Microsoft\Office\15.0\Word\Options ...
- DB2对年份的处理Year()
public DataSet GetCustomerAllocListByQC(CustomerAllocQueryDataContract aQC) { StringBuilder sql = ne ...
- mysql之视图
视图 视图是虚拟的表.与包含数据的表不一样,视图只包含使用时动态检索数据的查询. 理解视图最好的办法就是来看一下例子: SELECT cust_name , cust_contact FRO ...
- Eclipse导入工程中文乱码问题
此文引用自eclipse导入工程中文乱码问题,作者elleniou. 关于Eclipse导入工程中文乱码问题实在是一个非常令人头疼的,深感一定要彻底解决才算放心,故摘抄上文如下: eclipse之所以 ...
- Eclipse Java EE 编译器设置JSP默认编码
在windows-preferences-web-jsp files-encoding那里设置默认编码.如下图所示:
- JS初学的一些易错的知识点
1. false ,0 , "" ,undefined , null 在Boolean 环境下当成 false: null 在数值环境下当成 0: undefined 在数值 ...
- 【HDU 5030】Rabbit's String (二分+后缀数组)
Rabbit's String Problem Description Long long ago, there lived a lot of rabbits in the forest. One d ...
- nodejs上传图片并显示的例子
目标 1. 在浏览器地址栏输入“http://demos/start”,进入欢迎页面,页面有一个文件上传表单: 2. 选择一张图片并提交表单,文件被上传到"http://demos/uplo ...
- Android开发环境的安装 Eclipse
Android开发环境的安装 1 IDE Android可以使用开发的IDE有Eclipse 或者 Android Studio.Android Studio还处于v 0.1.x版本,是early a ...
- 在windows系统上安装VMware Workstation虚拟机,然后在虚拟机VMware Workstation上安装linux系统,在linux系统安装xshell的服务端,在windows系统上安装xshell。用windows系统上的xshell连接到linux
第一步:安装xshell: 去百度 xshell ,然后安装一下就可以了.就是普通的软件安装,在这里不做过多的接收. 第二步:安装虚拟机VMware Workstation 百度安装,不做过介绍 ...