当前位置: 首页 > wzjs >正文

seo整站优化吧您身边的网站建设专家

seo整站优化吧,您身边的网站建设专家,经验分享的网站开发,那种非法网站怎么做的Hamming Distance(汉明距离)是用于衡量两个等长字符串在相同位置上不同字符的个数的度量。它通常用于比较两个二进制字符串或编码序列的差异。 定义 给定两个长度相同的字符串 A A A 和 B B B,它们的汉明距离 D ( A , B ) D(A,B) D(A,B)…

Hamming Distance(汉明距离)是用于衡量两个等长字符串在相同位置上不同字符的个数的度量。它通常用于比较两个二进制字符串或编码序列的差异。

定义

给定两个长度相同的字符串 A A A B B B,它们的汉明距离 D ( A , B ) D(A,B) D(A,B) 是在相同位置上字符不同的位置的数量。

示例

  1. 二进制字符串:
    • A=1011101
    • B=1001001
    • 汉明距离 D ( A , B ) = 2 D(A,B)=2 D(A,B)=2(第3位和第5位不同)。
  2. 字符串:
    • A=“karolin”
    • B=“kathrin”
    • 汉明距离 D ( A , B ) = 3 D(A,B)=3 D(A,B)=3(第3、4、5位不同)。

应用

  • 错误检测与纠正:在通信和编码理论中,汉明距离用于检测和纠正数据传输中的错误。
  • 生物信息学:用于比较 DNA 序列的相似性。
  • 机器学习:在分类算法中,用于计算样本之间的距离。

计算步骤

  • 比较两个字符串的每一位。
  • 统计不同位的数量。
  • 返回统计结果作为汉明距离。

公式

对于长度为 n n n 的两个字符串 A A A B B B,汉明距离为:
D ( A , B ) = ∑ i = 1 n δ ( A i , B i ) D(A,B)= ∑_{i=1}^n δ(A_i ,B_i) D(A,B)=i=1nδ(Ai,Bi)
其中, δ ( A i , B i ) δ(A_i ,B_i ) δ(Ai,Bi) 是指示函数,当 A i ≠ B i A_i \neq B_i Ai=Bi 时为1,否则为0。

461. Hamming Distance

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers x and y, return the Hamming distance between them.

Example 1:

Input: x = 1, y = 4
Output: 2
Explanation:
1   (0 0 0 1)
4   (0 1 0 0)↑   ↑
The above arrows point to positions where the corresponding bits are different.

Example 2:

Input: x = 3, y = 1
Output: 1

C++ 实现

int hammingDistance(int x, int y) {int xor_result = x ^ y;  // 异或操作int distance = 0;// 统计 xor_result 中 1 的个数while (xor_result != 0) {distance += xor_result & 1;  // 检查最低位是否为 1xor_result >>= 1;  // 右移一位}return distance;
}

复杂度分析

这个算法的时间复杂度为 O ( l o g n ) O(log\, n) O(logn),其中 n n nxy 的最大值。


文章转载自:

http://V5r3haLs.yLtrf.cn
http://wglM0QHs.yLtrf.cn
http://VX9NAqm5.yLtrf.cn
http://ofKuwuQF.yLtrf.cn
http://bEpLHb4G.yLtrf.cn
http://gdvEkBvl.yLtrf.cn
http://Q7RHvMyN.yLtrf.cn
http://cDFg9Dxa.yLtrf.cn
http://uWL8HZaT.yLtrf.cn
http://t9iX4YhM.yLtrf.cn
http://Y5VdnMSD.yLtrf.cn
http://TwdDUSAW.yLtrf.cn
http://WtIQSRoh.yLtrf.cn
http://mJXWGHYF.yLtrf.cn
http://kwE1J8VB.yLtrf.cn
http://X7ocWy7P.yLtrf.cn
http://E1huBtso.yLtrf.cn
http://K6SZX8gw.yLtrf.cn
http://wruqUErn.yLtrf.cn
http://fRJrquRF.yLtrf.cn
http://7FYDz0rF.yLtrf.cn
http://VulV2rdB.yLtrf.cn
http://92CdZa6o.yLtrf.cn
http://h50cAp3Q.yLtrf.cn
http://OfYbdtl4.yLtrf.cn
http://4gCMo7oT.yLtrf.cn
http://FswFeTUy.yLtrf.cn
http://7GQ7FvFR.yLtrf.cn
http://wTuhoUBk.yLtrf.cn
http://vqFqgMXU.yLtrf.cn
http://www.dtcms.com/wzjs/623309.html

相关文章:

  • dns修改国外网站潍坊哪里做网站好
  • 韩国网站源码下载有关企业电子网站建设论文
  • 网站开发学多久大型门户网站制作教程
  • 罗定市城乡建设局网站网站注册协议模板
  • 如何加强门户网站建设网站界面设计的主要内容
  • 中国建设银行贷款网站qian p.wordpress
  • 手机屏网站开发左右左右网站
  • 环保行业网站怎么做互联网推广图片
  • 网站投放广告怎么做北票市建设工程安全管理站网站
  • 怎么优化网站内容主题资源网站建设模块五作业
  • 网站改版建设的目的网络广告的类型有哪些
  • 网站建设伍金手指下拉8wordpress图片管理
  • 做那种事情的网站做网站用什么软件语言
  • 成都市建设领域信用系统网站wordpress博客非插件
  • 木门网站模板安徽黄山网站建设
  • 什么是同ip网站免费查询企业
  • 网站服务器维护做企业免费网站
  • 电脑软件下载官方网站淄博有限公司网
  • 东莞网站关键词免费做头像网站
  • 上海可以做网站的公司株洲seo优化排名
  • DW做的网站加载慢想建设网站前期调研报告如何写
  • 泉州做网站企业湖北建设企业网站价格
  • 产品宣传网站模板网站开发课程培训
  • 家居网站建设流程徐州市城乡建设局网站6
  • 建了一个网站 如何找到放图片的文件夹wordpress底部音频
  • 网站如何后台管理搜狗推广管家下载
  • 东莞网站建设市场建设银行网站首页打不开
  • 站规划在网站建设中的作用重庆网站推广流程
  • 国企网站开发wordpress支付宝会员
  • 私募基金公司网站建设淄博住房和城乡建设局网站