Coursera Algorithm II PA2 Q2

题意:

what is the largest value of k such that there is a k-clustering with spacing at least 3?  That is, how many clusters are needed to ensure that no pair of nodes with all but 2 bits in common get split into different clusters?

即, 海明距离小于等于 2 的所有点要被聚集到一个 cluster 中

输入: 

[first bit of node 1] … [last bit of node 1]
[first bit of node 2] … [last bit of node 2]

For example, the third line of the file “0 1 1 0 0 1 1 0 0 1 0 1 1 1 1 1 1 0 1 0 1 1 0 1″ denotes the 24 bits associated with node #2.

输出:

what is the largest value of k such that there is a k-clustering with spacing at least 3? That is, how many clusters are needed to ensure that no pair of nodes with all but 2 bits in common get split into different clusters?

思路:

1. 将所有的点放入 hashtable 中

2. 遍历 hash table 中的所有点 p,  分别找出与 p 海明距离为 0, 1, 2 的点, 并将其合并

细节:

1. 实现 hash table 的数据结构式 unordered_multimap

2. 寻找与某点 p 海明距离为 0 的点, 通过hash table 可以在 o(1) 的时间内完成, 这是本题的基础

3. 寻找与某点 p hash 距离为 1 的点, 相当于把 p 的某一位翻转变成 p’, 然后找出与 p’ 海明距离为 1 的点

4. 海明距离为 2 同理

5. 用到带路径压缩的并查集

Submit original work, copying violates the class Honor Code

转载于:https://www.cnblogs.com/zhouzhuo/p/3758244.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值