English 中文(简体)
如何检查在电网上选定的电池是否构成隧道?
原标题:How to check if selected cells on a grid form a tunnel ?

鉴于每个囚室的电网分布图,每个囚室都可以用乳房(x, y)和这种囚室的矢量加以描述,我(自然)如何检查这些囚室是否构成隧道,如。 它们是:all,垂直或横向上下调? 但是,如果我只想看一下它们中的“ ”(而不是all)是否一致?

All are lines up             Most are lined up      Not lined up

                             C                       C C C
 C C C C C C C C             C C C C C C C C         C   C C C
                                 C                   C C C C
                                                         C C
最佳回答
问题回答

You could do a histogram of the x and y coordinates of the cells. If all cells are lined up horizontally, you get only one y-value in your histogramm and lots of consecutive x-values, which all occur only one times. Vertically is the same with x and y flipped.

If you want to check, if most of them are lined up, search for the value in the histogram, which has the most occurences (longest possible tunnel) and check the cells with that x or y-coordinate, if they are lined up (that is: their y or x-coordinates (depending on wheter x or y was used in the previous step) are consecutive without a gap (maybe sort them first)) If they are not, search for the second highest occurrence value, ...

如果你通过首先检查其<代码>y坐标为平方,则通过<代码>x对左边进行协调和反向,以检查差距。 利用对面坐标检查垂直隧道。

For the approximate check you will have to clarify what you mean by "most".





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签