简体   繁体   English

如何解决中间块问题(考虑边缘块并将任何块留在行中间)

[英]how to solve the middle block problem(consider edge blocks and leave any block in the middle of row)

I need to solve this algorithm problem. 我需要解决此算法问题。 In the diagram, there are many rows with different no. 在该图中,有许多行带有不同的编号。 of blocks. 块。 Each block is either good or bad. 每个块是好是坏。 The block with no. 没有的块。 1 on it is good block and rest are all bad. 1对它的好处是阻止,休息都不好。 I need to do the grouping of these blocks in 2 in order to find whether the resultant of these groupings is good or bad. 我需要在2中对这些块进行分组,以便确定这些分组的结果是好是坏。 If I make a group of 2 , I will check if all the blocks are having '1' on it. 如果以2为一组,则将检查所有块上是否都带有“ 1”。 If yes, then the resultant block is good, otherwise bad. 如果是,则结果块为好,否则为坏。

Problem: while doing groupings of blocks, I always have to consider the blocks that are on the edges. 问题:在对块进行分组时,我总是必须考虑边缘上的块。 If the row has odd number of blocks(lets say 9) and I'm making group of 2, then the middle block(5th block) has to be ignored, the blocks on the edges should get preference with respect to middle block. 如果该行具有奇数个块(假设为9)并且我将2个组设为一组,则必须忽略中间块(第5个块),则边缘上的块应相对于中间块具有优先级。 I don't know how to solve the problem as I'm confused with the part of ignoring the middle block in case of odd no. 我不知道如何解决该问题,因为我对在出现奇数时忽略中间块的部分感到困惑。 of blocks.It can ignore any block(near to middle block) but have to consider the blocks on the edges. 它可以忽略任何块(靠近中间块),但必须考虑边缘上的块。

So basically, First I need to find if the row has odd/even no.of blocks according to the groupsize which is 2. Then if odd no. 因此,基本上,首先我需要根据分组大小为2的行来查找行是否具有奇数/偶数块。 of blocks are here, leave the middle one and make a group with blocks on edges and find the result if the resultant is good or bad. 的块位于此处,离开中间的块,并在边缘形成一个块,然后根据结果的好坏找到结果。

In the inputs, I have the X and Y co-ordinate of each and every block and its information as the block is good or bad. 在输入中,我具有每个块的X和Y坐标,以及块的好坏,它的信息。

在此处输入图片说明

It seems like throwing away the exact middle block isn't a good solution. 似乎丢掉确切的中间块并不是一个好的解决方案。 With a row of size 7, you should be able to make 3 pairs, but if you discard the center one, you'll only get two pairs usable. 一排7号字样,您应该可以制作3对,但如果丢掉中间的1对,则只能得到两对可用。

Try taking blocks from both ends alternately: A pair from the left, then a pair from the right, then the next pair inward from the left. 尝试从两端交替取下积木:从左开始一对,然后从右开始一对,然后从左向内再进入另一对。 When your two pointers (or indexes) cross in the middle, you're done with the row. 当两个指针(或索引)在中间交叉时,该行就完成了。 When necessary you'll discard a block as near to the middle as possible, and you won't need any special case for even vs odd. 必要时,您将丢弃尽可能靠近中间的块,并且偶数与奇数不需要任何特殊情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM