Tag: 算法

如何查找集合的所有分区

我有一套不同的价值观。 我正在寻找一种方法来生成该集合的所有分区,即将集合划分为子集的所有可能方式。 例如,集合{1, 2, 3}具有以下分区: { {1}, {2}, {3} }, { {1, 2}, {3} }, { {1, 3}, {2} }, { {1}, {2, 3} }, { {1, 2, 3} }. 由于这些是数学意义上的集合,因此顺序无关紧要。 例如, {1, 2}, {3}与{3}, {2, 1} ,不应该是单独的结果。 可以在Wikipedia上找到集合分区的完整定义。

用C#实现Hoey Shamos算法

好的,我现在从我当前的算法中获取正确的信息! 但是,要检查700,000个多边形,这太慢了! 上一期是固定的(My Line2D intersectsWith方法不正确) 现在这是确定我的瓶颈的问题! 该算法假设为O(nlog-n),因此它应该更快。 我的intersectsWith方法看起来不能更快,但我会发布它的代码,万一我错了 编辑:添加了IComparable接口 我读取线段交叉点的方法。 为了便于阅读,省略了一些代码。 public class Line2D : IComparable { public Line2D(XYPoints p1, XYPoints p2) { } public bool intersectsLine(Line2D comparedLine) { if ((X2 == comparedLine.X1) && (Y2 == comparedLine.Y1)) return false; if ((X1 == comparedLine.X2) && (Y1 == comparedLine.Y2)) return false; if (X2 == comparedLine.X1 && Y2 […]