【本文链接】

http://www.cnblogs.com/hellogiser/p/hamming-distance.html

介绍

在信息领域,两个长度相等的字符串的海明距离是在相同位置上不同的字符的个数,也就是将一个字符串替换成另一个字符串需要的替换的次数。

例如:

xxxxyyxxxxzz的海明距离是2;

111100 和 111111 的海明距离是2;

对于二进制数字来说,海明距离的结果相当于a^b结果中1的个数。

【字符串】

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
/*
    version: 1.0
    author: hellogiser
    blog: http://www.cnblogs.com/hellogiser
    date: 2014/5/30
*/
// hamming distance of two strings
unsigned hamdist(const char *str1, const char *str2)
{
    // aaabb aaacc
    if (str1 == NULL || str2 == NULL)
        ;

int len1 = strlen(str1);
    int len2 = strlen(str2);
    if (len1 != len2)
        ;

;
    while(*str1 && *str2)
    {
        dist += (*str1 != *str2) ? ;
        str1++;
        str2++;
    }
    return dist;
}

【数字】

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
/*
    version: 1.0
    author: hellogiser
    blog: http://www.cnblogs.com/hellogiser
    date: 2014/5/30
*/
// hamming distance of two integer 0-1 bits
unsigned hamdist(unsigned x, unsigned y)
{
    //  11111 11100
, val = x ^ y; // XOR

// Count the number of set bits
    while(val)
    {
        ++dist;
        val &= val - ;
    }

return dist;
}

【参考】

http://blog.csdn.net/fuyangchang/article/details/5637464

http://en.wikipedia.org/wiki/Hamming_distance

http://my.oschina.net/u/1401481/blog/223223

【本文链接】

http://www.cnblogs.com/hellogiser/p/hamming-distance.html

64. 海明距离(Hamming Distance)的更多相关文章

  1. 海明距离hamming distance

    仔细阅读ORB的代码,发现有很多细节不是很明白,其中就有用暴力方式测试Keypoints的距离,用的是HammingLUT,上网查了才知道,hamming距离是相差位数.这样就好理解了. 我理解的Ha ...

  2. 477. Total Hamming Distance总的二进制距离

    [抄题]: The Hamming distance between two integers is the number of positions at which the correspondin ...

  3. Hamming Distance二进制距离

    [抄题]: The Hamming distance between two integers is the number of positions at which the correspondin ...

  4. Tag Archives: 海明距离

    在前一篇文章 <海量数据相似度计算之simhash和海明距离> 介绍了simhash的原理,大家应该感觉到了算法的魅力.但是随着业务的增长 simhash的数据也会暴增,如果一天100w, ...

  5. 海量数据相似度计算之simhash和海明距离

    通过 采集系统 我们采集了大量文本数据,但是文本中有很多重复数据影响我们对于结果的分析.分析前我们需要对这些数据去除重复,如何选择和设计文本的去重算法?常见的有余弦夹角算法.欧式距离.Jaccard相 ...

  6. Matlab计算两集合间的海明距离

    一.问题描述 B1[1 2 3 4 5 6 7 8 9] B2[12 13 14 21 31 41 51  1 1 81 1 1] 两个十进制矩阵,行数不一样,分别是n1和n2,列数必须一致,为nwo ...

  7. 使用simhash以及海明距离判断内容相似程度

    算法简介 SimHash也即相似hash,是一类特殊的信息指纹,常用来比较文章的相似度,与传统hash相比,传统hash只负责将原始内容尽量随机的映射为一个特征值,并保证相同的内容一定具有相同的特征值 ...

  8. [LeetCode] Total Hamming Distance 全部汉明距离

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  9. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

随机推荐

  1. Json-转换

    js转换 引用json.js(将json格式转换成字符串 var name = document.getElementById("name").value; var retries ...

  2. PowerDesigner-如何导出建表sql脚本

    1 按照数据库类型,切换数据库. Database-> Change Current DBMS... 2 生成sql脚本 Database -> Database Generation 的 ...

  3. Fedora和Ubuntu下安装OpenGL开发环境配置

    Fedora下OpenGl开发环境配置 开发OpenGL工程需要3个库文件和对应的头文件: libglut.so,libGLU.so,libGL.so, gl.h ,glu.h, glut.h 这些库 ...

  4. [IOS UICollectionView模版]

    创建CollectionCell模版: 1.新建类CollectionCell继承自UICollectionViewCell 2.新建Xib,命名为CollectionCell.xib a.选中Col ...

  5. Codeforces 650B Image Preview

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  6. c++实现快排出现错误

    #include"header_file.h" using namespace std; void swap(int a,int b) { int t; t=a; a=b; b=t ...

  7. html input file标签的上传文件 注意点

    文件上传框  代码格式:<input type=“file” name=“...” size=“15” input enctype="multipart/form-data“ maxl ...

  8. Apache22中配置虚拟主机(Apache VirtualHost)

    Apache VirtualHost的作用就是可以让一个apache为多个域名服务,相当于一个服务器挂了N多个网站,举个例子: 我的apache服务器,ip为x.x.x.x,我有两个域名www.too ...

  9. c语言 函数传输传递的三种方式(值、指针、引用)

    本文摘自<彻底搞定c指针> 一.三道考题开讲之前,我先请你做三道题目.(嘿嘿,得先把你的头脑搞昏才行……唉呀,谁扔我鸡蛋?)考题一,程序代码如下:void Exchg1(int x, in ...

  10. C#操作XML类

    XML转换成HTML 1.//装载xsl XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("output. ...