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) ...
随机推荐
- Vi的使用
Vi的使用: 范例一: 使用Vi进入一般模式: [root@dsetl lp]# vi test1.txt 范例二:按下i键进入编辑模式,开始编辑文字 -- INSERT – 范例三:按下[ESC]键 ...
- 无线Ad-hoc网络的关键技术之路由(转)
无线Ad-hoc网络的关键技术之路由http://network.51cto.com/art/201003/189719.htm
- LINUX进程控制
1. 引言 一个程序是存储在文件中的机器指令序列.一般它是由编译器将源代码编译成二进制格式的代码.运行一个程序意味着将这个机器指令序列载入内存然后让处理器(cpu)逐条执行这些指令. 在Unix术语中 ...
- js小技巧(一)
事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcE ...
- JS加载时间线
1.创建Document对象,开始解析web页面.解析HTML元素和他们的文本内容后添加Element对象和Text节点到文档中.这个阶段document.readyState = 'loading' ...
- Linux下ps -ef和ps aux的区别及格式详解
Linux下显示系统进程的命令ps,最常用的有ps -ef 和ps aux.这两个到底有什么区别呢?两者没太大差别,讨论这个问题,要追溯到Unix系统中的两种风格, System V风格和BSD 风格 ...
- 简单验证码识别 tessnet2
今天突然间对识别验证码感兴趣,于是网上搜了一下 最简单的是引用tessnet2.dll,然后通过它来识别,代码如下 private void button1_Click(object sender, ...
- Hbase Shell命令
1 启动HBase shell 2 HBase shell 命令 3 我们将以“一个学生成绩表”的例子来详细介绍常用的 HBase 命令及其使用方法. 这里 grad 对于表来说是一个列,course ...
- Linux command: usermod -- 改变用户状态
应用举例: 1. usermod -g newuser newuser force use GROUP as new primary group. 一般时候是默认的,也是必须的(不能更改).2. 指定 ...
- switch中的default的位置
[转载]http://hi.baidu.com/dannie007zxl/item/5d0c3185577df719c3162724 有的时候,我们对身旁自认为熟悉的东西,却发现很难去给出准确的回答. ...