在2维数组上查找符号块 [英] Finding blocks of symbols on a 2dimensional array

查看:60
本文介绍了在2维数组上查找符号块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在创建一个玩游戏的程序。在NxN方板上玩这个游戏

。在董事会的每个位置,我们可能会得到一个或两个球。以下面的5x5板为例(x:球,

o:空格)。


xxoox

xoooo

ooxxo

oooxx

xxooo


我想写一个计算球块数的函数
$ b特定董事会上的$ b。例如,上面的板有4个球块

(一个或多个球被空的空间包围)。


问题是我想不出任何优雅算法

计算这个数字。


欢迎任何想法...

感谢您的时间。

解决方案



" efialtis" < EF ****** @ efialtis.gr>在消息中写道

news:pa **************************** @ efialtis.gr ... < blockquote class =post_quotes>大家好,

我正在创建一个玩游戏的程序。游戏在NxN方板上播放。在董事会的每个位置,我们可能有一个球或没有球。以下面的5x5板为例(x:球,
o:空的空间)。

xxoox
xoooo
ooxxo
oooxx
xxooo

我想写一个函数来计算特定电路板上的球块数量。例如上面的板有4个球块
(1个或多个球被空的空间包围)。

问题是我想不出任何优雅的算法来计算这个号码。




听起来像是''转换为二进制'',然后对我做了一些调整。


2006-01-09,efialtis< ef ****** @ efialtis.gr>写道:


xxoox
xoooo
ooxxo
oooxx
xxooo

我想写一个函数计算特定电路板上的球块数量。例如,上面的板有4个球块
(一个或多个球被空的空间包围)。




这些是否被视为有两个块或一个街区:


ox

xo





ooxo

ooox

oooo

oooo




-

Ioan - Ciprian Tandau

tandau _at_ freeshell _dot_ org(希望现在还不算太晚)

(...而且它仍然有效......)


2006-01-09,efialtis< ef ****** @ efialtis.gr>写道:

大家好,

我正在创建一个玩游戏的程序。游戏在NxN方板上播放。在董事会的每个位置,我们可能有一个球或没有球。以下面的5x5板为例(x:球,
o:空的空间)。

xxoox
xoooo
ooxxo
oooxx
xxooo

我想写一个函数来计算特定电路板上的球块数量。例如上面的板有4个球块
(1个或多个球被空的空间包围)。

问题是我想不出任何优雅的算法来计算这个号码。

欢迎任何想法......
感谢您的时间。




某种泛洪填充算法,也许? [这并不属于

这个新闻组]


Hi to all,

I am creating a program which plays a game. The game is played
on a NxN square board. In every position of the board we may have
a ball or not. Take for example the following 5x5 board ( x : ball,
o : empty space).

x x o o x
x o o o o
o o x x o
o o o x x
x x o o o

I want to write a function which calculates the number of ball blocks
on a specific board. For example the above board has 4 ball blocks
(1 or more balls being surrounded by empty spaces).

The problem is that i cannot think of any elegant algorithm to
calculate this number.

Any idea welcome...
Thank you for your time.

解决方案


"efialtis" <ef******@efialtis.gr> wrote in message
news:pa****************************@efialtis.gr...

Hi to all,

I am creating a program which plays a game. The game is played
on a NxN square board. In every position of the board we may have
a ball or not. Take for example the following 5x5 board ( x : ball,
o : empty space).

x x o o x
x o o o o
o o x x o
o o o x x
x x o o o

I want to write a function which calculates the number of ball blocks
on a specific board. For example the above board has 4 ball blocks
(1 or more balls being surrounded by empty spaces).

The problem is that i cannot think of any elegant algorithm to
calculate this number.



Sounds like a ''convert to binary'' and then do some bit twiddling to me.


On 2006-01-09, efialtis <ef******@efialtis.gr> wrote:


x x o o x
x o o o o
o o x x o
o o o x x
x x o o o

I want to write a function which calculates the number of ball blocks
on a specific board. For example the above board has 4 ball blocks
(1 or more balls being surrounded by empty spaces).



Are these considered as having two blocks or one block:

ox
xo

and

ooxo
ooox
oooo
oooo
?

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it''s not too late)
(... and that it still works...)


On 2006-01-09, efialtis <ef******@efialtis.gr> wrote:

Hi to all,

I am creating a program which plays a game. The game is played
on a NxN square board. In every position of the board we may have
a ball or not. Take for example the following 5x5 board ( x : ball,
o : empty space).

x x o o x
x o o o o
o o x x o
o o o x x
x x o o o

I want to write a function which calculates the number of ball blocks
on a specific board. For example the above board has 4 ball blocks
(1 or more balls being surrounded by empty spaces).

The problem is that i cannot think of any elegant algorithm to
calculate this number.

Any idea welcome...
Thank you for your time.



some kind of flood fill algorithm, maybe? [this doesn''t really belong in
this newsgroup]


这篇关于在2维数组上查找符号块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆