将两个连续排序的整数集映射到一个整数集
我正在尝试将两个连续排序的整数集(具有可能不同的项目数)映射到保留线性间距的单个连续排序的整数集。
例如 答:{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 Cfor (int i = 0; i < A.Count(); i++)
{
mapping.Add(A.ElementAt(i),
(i*((numBuckets - 1)/(A.Count() -
1))).ToString()); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设集合 C 的大小为 |C| = Nc 对于 A 组,|A| = Na。然后,如果要将 A 映射到 C,请让第一个元素相互映射,然后跳过元素
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