算法problem-附加了图象 [英] Algorithm problem- with the picture attached

查看:115
本文介绍了算法problem-附加了图象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我附上我在这里已经表明了,我需要核对好/坏块图的画面。基本上,我有每个块的行和列数的大小的信息。我也知道,如果行有偶数或奇数块。

I am attaching a picture where I have shown the diagram for which I need to check the good/bad blocks. Basically, I have the information of size of each block and number of rows and column. I also know if the row has even or odd number of blocks.

我需要2个街区集群,并检查得到的块(与2的组合)是好还是坏。如果2块都不错,然后将得到的是好块,否则不好。

I need to make a cluster of 2 blocks and check if the resultant block(with the combination of 2) is good or bad. If the 2 blocks are good, then the resultant is good block , otherwise bad.

我需要知道它的算法。

I need to know the algorithm of it.

如果该行有块奇数,我忽略了中间块,并考虑到最后的块。

If the row has odd numbers of blocks, I am ignoring the middle block and considering the last blocks.

该图是在圆的形状,但在圆周上的块被忽略。所以,我有如图所示画面只考虑中间块。

The diagram is in the shape of circle but the blocks on the circumference are ignored. So, I have to consider only the middle block as shown in the picture.

我需要遍历每一行,使2组,找到的结果。但是,如果该行有块奇数,忽略了中间的一个,并进行了小组最后两个街区的拐角处。

I need to iterate over each row, make a group of 2, find the result. But if the row has odd number of blocks, ignore the middle one, and make a group of last two blocks at the corner.

在圈内的形状如上图,是真正的数字。

The shape inside the circle as shown in picture, is the real figure.

我想,我已经给了足够的信息,这个时候。

I guess, I have given enough information this time.

请注意:在本例中,我使两个一组,但我需要的一组2,3或4个块的行中,就像一个通用的情况。如果组中的任何块是坏,全团是坏的一组,3或4,我是否需要写code在Visual Basic语言。大小,没有。图中所示的行中的块是不是真正的data.It仅仅是一个例子。

NOTE: In this example, I making a group of two, but I need to make a group of 2, 3 or 4 blocks in the row ,just like a generic case. If any block in the group is bad,the whole group is bad whether its a group of ,3, or 4.I need to write the code in visual basic language. The size, no. of blocks in the row shown in the picture are not the real data.It is just an example.

我有一些类型的解决方案,检查每块及其周围块,是不正确的。但能把它以这种方式来完成:

I have some type of solution that checks for each block and its surrounding block which is not right. But Can it be done in this way:

下面的解决方案:

如果你增加两个,再一个badBlock意味着无论对任何一方都还不错,导致3坏的

If you are adding two, then one badBlock means both on either side are also bad leading to 3 bad on

1)建立N×N个结构的数组{布尔切圆,badBlock,badGroup;}其中内切圆是真实的,如果该块是在圈内,badBlock是真实的,如果该块是在一个糟糕的,最初badGroup是假的

1) Set up NxN array of struct {bool inCircle, badBlock, badGroup;} Where inCircle is true if the block is in the circle, badBlock is true if the block is a bad on and initially badGroup is false.

int length=2;
for (int i=0; i<N;i++)
  for(int j=0; j<N;j++)
     if(array[i,j].badBlock){
       for(int x=-length;x<=length;x++)
           if(i+x>=0 and i+x<N and array[i+x,j].inCircle) then array[i+x,j].badGroup=true; 
       for(int y=-length;y<=length;y++)
           if(j+y>=0 and j+y<N and array[i,j+y].inCircle) then array[i,j+y].badGroup=true; 
}

我还知道X和Y坐标的每个块的

I also the know the x and Y co-ordinate of each block.

推荐答案

简单的递归会做,伪code:

simple recursion will do, pseudo-code:

GroupSize = 2;
bool Calc(row, start, end)
{
   if (end-start <= GroupSize -1) return true;
   if (end - start < GroupSize*2) //Single group in the middle, but smaller than 2 groups (calculate only the first group size)
   {
      bool result = true;
      for (i = start ; i < GroupSize; i++)
      {
         result = result && row[i];
      }
   } 
   else
   {
       return Calc(row, start, start + GroupSize) && Calc(row,end-GroupSize,end) && GroupSize(row, start + GroupSize,end-GroupSize);

   }
}

类似的东西。
这样做是为了递归地计算该行的两侧,然后发送中间一些更多计算

Something like that.
The idea is to recursively calculate both sides of the row and then send the middle for some more calculating.

递归可能是最简单的方法(或并不适合所有人),BU任何递归可以变成一个循环。

Recursion might be simplest way (or not for everyone), bu any recursion can be turned into a loop.

这篇关于算法problem-附加了图象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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