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 ...
随机推荐
- TMS320F28335项目开发记录1_CCS的使用介绍
CCS使用介绍 一.前言 本系列文章记录本人实际项目开发时对ti的DSP28335,以及CCS开发环境等的学习与记录,相对于2812来说,28335的资料还是比較少的,只是原理是相通的,28335说白 ...
- 微信团队分享:iOS版微信的高性能通用key-value组件技术实践
本文来自微信开发团队guoling的技术分享. 1.前言 本文要分享的是iOS版微信内部正在推广和使用的一个高性能通用key-value 组件的技术实践过程,该组件在微信内部被命名为MMKV(以下简称 ...
- python——TypeError: 'str' does not support the buffer interface
import socket import sys port=51423 host="localhost" data=b"x"*10485760 #在字符串前加 ...
- spring--百度百科
Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Development a ...
- 数据结构之---C语言实现最小生成树之prim(普里姆)算法
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- 攻克了Cocoapods Undefined symbols for architecture _OBJC_CLASS_xxxx的问题,辛苦死我了,记录下之后有空在研究
网上找了一大包将尽3个小时没有解决,原本以为是我升级到10.10的原因,把cocoapod 重装 stackoverflow google 用尽了也不知道为啥 结果是这个样子的 编译出现这个.... ...
- S2S3H4 整合代码示例
主要代码列举: web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app versi ...
- poj 2601 Simple calculations
Simple calculations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6559 Accepted: 32 ...
- ORCAD应用小技巧
1.位号复制 递增和不变 2.netlist log信息 3.off page页码对其 4.批量修改off page符号命名的方法 5.批量修改电源符号 6.capture中instance和Occu ...
- TensorFlow学习笔记 补充2—— 生成特殊张量
1. 生成tensor tf.zeros(shape, dtype=tf.float32, name=None) tf.zeros_like(tensor, dtype=None, name=None ...