G - Oil Deposits(dfs)
G - Oil Deposits
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
Sample Output
0
1
2
2
//普通的dfs,把四周都遍历就行,计算有几块
#include <iostream>
#include <string.h>
using namespace std; char map[][];
int way[][];
int all;
int m,n; void read_map()
{
memset(way,,sizeof(way));
for (int i=;i<=m;i++)
{
for (int j=;j<=n;j++)
{
cin>>map[i][j];
}
} } void dfs(int x,int y)
{
way[x][y]=;
if (x+<=m&&map[x+][y]=='@'&&way[x+][y]==) dfs(x+,y);
if (x+<=m&&y->=&&map[x+][y-]=='@'&&way[x+][y-]==) dfs(x+,y-);
if (y->=&&map[x][y-]=='@'&&way[x][y-]==) dfs(x,y-);
if (y->=&&x->=&&map[x-][y-]=='@'&&way[x-][y-]==) dfs(x-,y-);
if (x->=&&map[x-][y]=='@'&&way[x-][y]==) dfs(x-,y);
if (x->=&&y+<=n&&map[x-][y+]=='@'&&way[x-][y+]==) dfs(x-,y+);
if (y+<=n&&map[x][y+]=='@'&&way[x][y+]==) dfs(x,y+);
if (y+<=n&&x+<=m&&map[x+][y+]=='@'&&way[x+][y+]==) dfs(x+,y+);
} int main()
{ while (cin>>m>>n)
{
if (m==&&n==) break; all=;
read_map();
for (int i=;i<=m;i++)
{
for (int j=;j<=n;j++)
{
if (map[i][j]=='@'&&way[i][j]==)
{
dfs(i,j);
all++;
}
}
}
cout<<all<<endl;
} return ;
}
G - Oil Deposits(dfs)的更多相关文章
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- 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 ...
- HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- UVa572 Oil Deposits DFS求连通块
技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...
- HDU 1241 Oil Deposits (DFS/BFS)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU-1241 Oil Deposits (DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU_1241 Oil Deposits(DFS深搜)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
- UVa 572 Oil Deposits(DFS)
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil ...
随机推荐
- Spine U3D整合流程问题
Spine U3D整合流程问题 What: 公司2d项目开发,动画外包的spine.本来在spine里面一切正常,但是导入u3d运行库的时候动画切换的时候原来的动画是好的,一旦切换了就乱帧了. 如下结 ...
- windows 7 提示升级到windows 10补丁
如果不需要这个提示,可以卸载KB3035583和KB2952664这两个系统更新补丁. other update:KB2976978 and KB2977759
- hibernate 悲观锁乐观锁
悲观锁和乐观锁是:在事务隔离机制中设置了ReadCommited的情况下,两种可以避免不可重复读的方式. 设置成读已提交是考虑到安全和处理速度,保证并发效率,但是在这个情况下仍然需要避免不可重复读 ...
- Quartz.net基于数据库的任务调度管理(Only.Jobs)
一 前言: 各大调度组件优缺点在这就不讨论了,使用Quartz.net是因为它可以执行秒级任务. Only.Jobs 项目通过将各Job存储在数据库中,启动一个专门的Job管理任务来循环调度各Job的 ...
- 转 iOS:NSAttributedString
NSAttributedString: http://blog.csdn.net/kmyhy/article/details/8895638 CTFramesetterSuggestFrameSize ...
- gm picture
console.log("ok") /*var images = require("images");var fs = require("fs&quo ...
- Android 4.4 全套源代码及子模块源代码的下载方法
博文<Android源代码下载--用git clone实现单个文件夹下载>介绍了採用git clone方法下载Android单个文件夹源代码的方法,这篇文章已经有四年的历史,这期间Goog ...
- android studio - 隐藏编辑器上面的导航条
菜单栏-“View”-"Navigation Bar"
- 203. Remove Linked List Elements【easy】
203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...
- linux系统之free命令详解
total used free shared buffers cached Mem: -/+ buffers/cache: Swap: 上面是free命令的执行结果,下面我来详细说说其中的含义: Me ...