HDU1241 Oil Deposits 2016-07-24 13:38 66人阅读 评论(0) 收藏
Oil Deposits
Problem Description
analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and
may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.
Input
n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either `*', representing the absence of oil, or `@', representing an oil pocket.
Output
Sample Input
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
Sample Output
0
1
2
2
————————————————————————————————————————————————————
#include<iostream>
#include<cmath>
using namespace std;
char map[105][105];
int m, n, t;
int dir[8][2] = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, {1,1} }; void dfs(int si, int sj)
{
if (si <= 0 || sj <= 0 || si > m || sj > n)
return;
for (int i = 0; i < 8; i++)
{
if (map[si + dir[i][0]][sj + dir[i][1]] != '*')
{
map[si + dir[i][0]][sj + dir[i][1]] = '*';
dfs(si + dir[i][0], sj + dir[i][1]);
}
}
return;
}
int main()
{
while (cin >> m >> n&&(m||n))
{
for (int i = 1; i <= m;i++)
for (int j = 1; j <= n; j++)
cin >> map[i][j];
t = 0;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
{
if (map[i][j] == '@')
{
map[i][j] = '*';
t++;
dfs(i, j);
}
}
printf("%d\n", t);
}
return 0; }
HDU1241 Oil Deposits 2016-07-24 13:38 66人阅读 评论(0) 收藏的更多相关文章
- POJ1087 A Plug for UNIX 2017-02-12 13:38 40人阅读 评论(0) 收藏
A Plug for UNIX Description You are in charge of setting up the press room for the inaugural meeting ...
- 百度地图-省市县联动加载地图 分类: Demo JavaScript 2015-04-26 13:08 530人阅读 评论(0) 收藏
在平常项目中,我们会遇到这样的业务场景: 客户希望把自己的门店绘制在百度地图上,通过省.市.区的选择,然后加载不同区域下的店铺位置. 先看看效果图吧: 实现思路: 第一步:整理行政区域表: 要实现通过 ...
- Power Network 分类: POJ 2015-07-29 13:55 3人阅读 评论(0) 收藏
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24867 Accepted: 12958 Descr ...
- IOS第三方数据库--FMDB 分类: ios技术 2015-03-01 09:38 57人阅读 评论(0) 收藏
iOS中原生的SQLite API在使用上相当不友好,在使用时,非常不便.于是,就出现了一系列将SQLite API进行封装的库,例如FMDB.PlausibleDatabase.sqlitepers ...
- Oracle错误IMP-00010: 不是有效的导出文件, 头部验证失败 分类: Oracle 2015-07-09 13:56 20人阅读 评论(0) 收藏
Oracle 11g的dmp备份文件导入到Oracle 10g,出现错误信息: Import: Release 10.2.0.1.0 - Production on 星期四 7月 9 13:47:04 ...
- UI基础:UILabel.UIFont 分类: iOS学习-UI 2015-07-01 19:38 107人阅读 评论(0) 收藏
UILabel:标签 继承自UIView ,在UIView基础上扩充了显示文本的功能.(文本框) UILabel的使用步骤 1.创建控件 UILabel *aLabel=[[UILabel alloc ...
- Hdu1969 Pie 2017-01-17 13:12 33人阅读 评论(0) 收藏
Pie Time Limit : 5000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissio ...
- HDU1312 Red and Black(DFS) 2016-07-24 13:49 64人阅读 评论(0) 收藏
Red and Black Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU1237 简单计算器 2016-07-24 13:34 193人阅读 评论(0) 收藏
简单计算器 Problem Description 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值. Input 测试输入包含若干测试用例,每个测试用例占一行,每行不超过 ...
随机推荐
- WAL 【转】
重做日志:每当有操作执行前,将数据真正更改时,先前相关操作写入重做日志.这样当断电,或者一些意外,导致后续任务无法完成时,系统恢复后,可以继续完成这些更改 撤消日志:当一些更改在执行一半时,发生意外, ...
- dowhile
public class TestDoWhile { /**do while 至少执行一次 先斩后奏 * 测试dowhile */ public static void main(String[] a ...
- time和datetime
一.time模块常用函数1. time()函数time()函数返回的是时间戳(timestamp).所谓时间戳指的是从1970年1月1日00:00:00开始按秒计算的偏移量.其他返回时间戳方式的函数还 ...
- python处理分隔大文件
4个.sql格式的文件,2G大小,直接插入mysql数据中,文件太大了,导入不进去. 太大的文件用python处理也很麻烦,处理不了,只能先分隔成小文件处理. 文件中数据格式:其中values里面的数 ...
- SOA (面向服务的架构)
面向服务的体系结构,是一个组件模型,它将应用程序的不同功能单元(称为服务)通过这些服务之间定义良好的接口和契约联系起来.接口是采用中立的方式进行定义的,它应该独立于实现服务的硬件平台.操作系统和编程语 ...
- python的range函数与切片操作符
range(start,stop,step)参数含义:start:计数从start开始.默认是从0开始.例如range(5)等价于range(0, 5);end:计数到end结束,但不包括end.例如 ...
- TZOJ 1242 求出前m大的数(预处理)
描述 给定一个包含N(N<=3000)个正整数的序列,每个数不超过5000,对它们两两相加得到的N*(N-1)/2个和,求出其中前M大的数(M<=10000)并按从大到小的顺序排列. 输入 ...
- Future设计模式
一.什么是Future模型: Future模式是多线程开发中非常常见的一种设计模式,它的核心思想是异步调用.这类似我们网上订餐订座,只要一个电话,客服就告诉我们已经预定成功(实际客服MM啥都还没做好) ...
- Apache虚拟主机/端口多开
Apache就是强大啊,简单配置一下就可以再开启另一个端口的web服务. 笔者最近使用XAMPP架设php服务端.有一些特别的需求:同样的代码,需要开始不同的端口, 协议类型提供web服务给客户端(h ...
- 【转】MEF程序设计指南二:Silverlight中使用CompositionInitializer宿主MEF
MEF可以在传统应用程序中使用(包括桌面的Winform.控制台程序和Web的ASP.NET),也可以在RIA的Silverlight中使用.在Silverlight中只是宿主的方式有所不同,实际上在 ...