算法问题 - 附图片 [英] Algorithm problem- with the picture attached

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

问题描述

我附上一张照片,我已经显示了我需要检查好/坏块的图表。基本上,我有各个块的大小和行数和列的信息。我也知道该行是否有偶数或奇数块。



我需要创建一个2个块的集群,并检查结果块(结合2)是好还是坏。如果2块好,那么结果是好块,否则不好。



我需要知道它的算法。



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



图形为圆形,但圆周上的块将被忽略。所以,我只需要考虑中间的块,如图所示。



我需要遍历每一行,使一组2,找到结果。但是,如果该行具有奇数个块,则忽略中间块,并在一个角落组成一组最后两个块。



如图所示,圆圈内的形状是真实的数字。



我猜,我有这次给了足够的信息。



注意:在这个例子中,我做了一组两个,但是我需要在一行中创建一组2,3或4个块,就像一般的案件。如果组中的任何块是坏的,整个组是坏的,不管它是一组,3或4.我需要用可视化的基本语言编写代码。大小,不。在图中显示的行中的块不是真实的数据。这只是一个例子。



我有一些类型的解决方案来检查每个块及其周围块是不对的。但是可以这样做:



这是解决方案:



如果你添加两个,那么一个

1)设置N * N数组struct {bool inCircle,badBlock,badGroup;}其中inCircle为true如果块在循环中,则badBlock是true,如果块是坏的,最初的badGroup是false。

  int length = 2; (int i = 0; i< N; i ++)
(int j = 0; j if(array [i,j] .badBlock){ (int x = -length; x <= length; x ++)
if(i + x> = 0和i + x< N和数组[i + x,j] .inCircle)阵列[I + X,j]的.badGroup = TRUE; (int y = -length; y< = length; y ++)
if(j + y> = 0和j + y }

我也知道每个块的x和Y坐标。 / p>

解决方案

简单递归会做,伪代码:

  GroupSize = 2; 
bool Calc(row,start,end)
{
if(end-start< = GroupSize -1)return true;
if(end-start< GroupSize * 2)//单个组在中间,但小于2组(仅计算第一组大小)
{
bool result = true; (i = start; i< GroupSize; i ++)

{
result = result&&&行[I];
}
}
else
{
return Calc(row,start,start + GroupSize)&& Calc(row,end-GroupSize,end)&& GroupSize(row,start + GroupSize,end-GroupSize);

}
}

这样的事情

这个想法是递归计算行的两边,然后发送中间进行一些更多的计算。



递归可能是最简单的方式(或不是每个人),任何递归都可以变成循环。


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.

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.

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.

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:

Here's solution:

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

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; 
}

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

解决方案

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.

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

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

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