将两个连续排序的整数集映射到一个整数集

发布于 2024-09-27 20:15:49 字数 591 浏览 0 评论 0原文

我正在尝试将两个连续排序的整数集(具有可能不同的项目数)映射到保留线性间距的单个连续排序的整数集。

例如 答:{1,2,3} 乙:{1,2,3,4} 可以映射到 C:{1,2,3,4,5,6,7} 经过 A:{1→1、2→4、3→7}并且 B:{1->1, 2->3, 3->5, 4->7}

手工完成这些都很好,但我很难概括。

分解问题,我需要找到(1)输出集中的桶数和(2)输入 - >输出映射

我在这里提供的解决方案:

// 输出C中有LCM(|A|-1,|B|-1)+1个桶

int numBuckets = LCM( A.Count()-1, B.Count()-1 ) + 1;

// 将A中的元素映射到A中的桶中 输出C

for (int i = 0; i < A.Count(); i++)
{ 映射.Add(A.ElementAt(i), (i*((numBuckets - 1)/(A.Count() - 1))).ToString()); }

I am trying to map two continuous sorted integer sets (with potentially differing number of items) to a single continuous sorted integer set preserving linear spacing.

e.g.
A: {1,2,3}
B: {1,2,3,4}
could map onto
C: {1,2,3,4,5,6,7}
by
A: {1->1, 2->4, 3->7} and
B: {1->1, 2->3, 3->5, 4->7}

It's pretty each to do these by hand, but I'm having trouble generalizing.

Decomposing the problems, I need to find (1) the number of buckets in the output set and (2) the input -> output mapping

My solution provided here:

// There are LCM(|A|-1,|B|-1)+1 buckets in output C

int numBuckets = LCM(
A.Count()-1, B.Count()-1 ) + 1;

// Map elements in A to buckets in
output C

for (int i = 0; i < A.Count(); i++)
{
mapping.Add(A.ElementAt(i),
(i*((numBuckets - 1)/(A.Count() -
1))).ToString()); }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动次打次papapa 2024-10-04 20:15:49

假设集合 C 的大小为 |C| = Nc 对于 A 组,|A| = Na。然后,如果要将 A 映射到 C,请让第一个元素相互映射,然后跳过元素

floor( (Nc-1)/(Na-1) )

Suppose the size of set C is |C| = Nc and for set A, |A| = Na. Then, if you want to map A to C, let the first elements map to each other and then skip elements by

floor( (Nc-1)/(Na-1) )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文