link:http://acm.hdu.edu.cn/showproblem.php?pid=4712

题意:给1e5个数字,输出这些数中,最小的海明码距离。

思路:距离的范围是0到20。而且每个数的数位都很有限的,然后一言不合开始

随机。随机算法虽然挺惊艳的,不过求随机算法成功概率,臣妾做不到啊!

总之,遇上暴力很难得到优化,但AC掉一片的题,随机算法这样的奇策应当信手

拈来!这是强大洞察之力的体现~

#include <iostream>
#include <algorithm>
using namespace std;
const int NICO = 100000+10;
int T, n, a[NICO];
int main()
{scanf("%d", &T);while(T--){scanf("%d", &n);for(int i=1;i<=n;i++){scanf("%X", &a[i]);}int ans = 22;for(int i=1;i<=500000;i++){int x = rand()%n+1;int y = rand()%n+1;if(x == y) continue;int v = a[x]^a[y];ans = min(ans, __builtin_popcountl(v));}printf("%d\n", ans);}
}

  

转载于:https://www.cnblogs.com/RUSH-D-CAT/p/6837654.html

HDU4712 Hamming Distance (随机化)相关推荐

  1. Leetcode 461. Hamming Distance JAVA语言

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

  2. [LeetCode] 461. Hamming Distance

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

  3. C++ hamming distance汉明距离算法(附完整源码)

    hamming distance汉明距离的算法 hamming distance汉明距离的算法的完整源码(定义,实现,main函数测试) hamming distance汉明距离的算法的完整源码(定义 ...

  4. LeetCode 461 Hamming Distance(汉明距离)

    Q:The Hamming distance between two integers is the number of positions at which the corresponding bi ...

  5. LeetCode之Hamming Distance

    1.题目 The Hamming distance between two integers is the number of positions at which the corresponding ...

  6. 461. Hamming Distance【数学|位运算】

    2017/3/14 15:23:55 The Hamming distance between two integers is the number of positions at which the ...

  7. LeetCode 461. Hamming Distance

    题目: The Hamming distance between two integers is the number of positions at which the corresponding ...

  8. C#LeetCode刷题之#461-汉明距离​​​​​​​(Hamming Distance)

    问题 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目. 给出两个整数 x 和 y,计算它们之间的汉明距离. 注意:0 ≤ x, y < 231. 输入: x = 1, y = ...

  9. 【LeetCode】461. Hamming Distance (java实现)

    2019独角兽企业重金招聘Python工程师标准>>> 原题链接 https://leetcode.com/problems/hamming-distance/ 原题 The Ham ...

最新文章

  1. C++中explicit关键字的作用
  2. 百度智能小程序正式开源,开发方案详解
  3. 使用Identity Server 4建立Authorization Server (6) - js(angular5) 客户端
  4. mysql不同的类的个数_Mysql数据库-SQL优化-统计某种类型的个数
  5. 这是一篇测试博文的文章
  6. 华中科技大学2005年计算机组成原理试题,华中科技大学200年计算机组成原理考研试题.doc...
  7. nginx开机启动脚本
  8. 黑客(一):黑客守则
  9. 华为手机怎样才算激活了_华为手机激活是怎么回事
  10. 超强数据恢复软件【含注册码】
  11. 雅思考试流程、需要具体注意些什么、怎么复习?
  12. openwrt的ipk包开发
  13. JavaScript设计模式之“单例模式“
  14. web表格制作--11.27
  15. 大学python教材实验七字典与集合答案_Python中的字典与集合
  16. 国内jQuery CDN
  17. windows下延时函数
  18. python 自动上色_Github | 线稿自动上色
  19. 使用Adobe Illustrator将EPS编辑为合适的论文图片
  20. Vivado 2019.1安装包下载

热门文章

  1. javascript 创建对象方式
  2. Kafka常用运维操作命令
  3. Linux之find常用命令汇总
  4. Halcon 基本算子释义
  5. 接口可以继承多个接口总结
  6. Codeforces Round #Pi (Div. 2) B. Berland National Library 模拟
  7. oj2894(贝尔曼福特模板)
  8. HTML 5中的tips两则
  9. HDOJ 1720 A+B Coming
  10. python闭包的应用场景_Python闭包函数定义与用法分析