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);
}
}

  

HDU4712 Hamming Distance (随机化)的更多相关文章

  1. hdu4712 Hamming Distance

    Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) To ...

  2. HDU 4217 Hamming Distance 随机化水过去

    Hamming Distance Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

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

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

  4. [LeetCode] Hamming Distance 汉明距离

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

  5. Total Hamming Distance

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

  6. Hamming Distance

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

  7. 461. Hamming Distance and 477. Total Hamming Distance in Python

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

  8. LeetCode Total Hamming Distance

    原题链接在这里:https://leetcode.com/problems/total-hamming-distance/ 题目: The Hamming distance between two i ...

  9. LeetCode Hamming Distance

    原题链接在这里:https://leetcode.com/problems/hamming-distance/ 题目: The Hamming distance between two integer ...

随机推荐

  1. 运行错误:应用程序无法启动因为并行配置不正确。the application has failed to start because its side-by-side configuration is incorrect 解决方法

    问题描述: 当电脑同时安装VS2008和VS2008 SP1时,编译出来的Visual C++程序的manifest 文件会默认引用VS2008的MFC版本和CRT版本.如下: <depende ...

  2. 基于均值漂移的三维网格分割算法(Mean Shift)

    mean shift算法是一种强大的无参数离散数据点的聚类方法,其在图像平滑.图像分割以及目标跟踪等方面都有着广泛的应用.[Yamauchi et al. 2005]基于mean shift算法提出了 ...

  3. unity插件开发——Selection

    Selection是一个静态类,它的主要功能是获取在project窗口中鼠标选择的对象或者是inspector窗口的当前显示的对象.它的字段有 activeGameObject activeInsta ...

  4. 关于JavaScript中连等赋值那点事

    今天看了前端网上关于JS的题目,其中有一道题目挺有意思的.如下 var a = b =10; (function(){ var a = b = 20; })(); console.log(a); co ...

  5. Kickstart无人值守安装系统

    1.导言 已经或未来将从事Linux系统运维工作的读者,经常会遇到一些机器式的重复的共走,例如:有时间同时上线几十甚至上百台服务器,而且需要我们在短时间内完成系统安装. q  光盘安装系统===> ...

  6. Hadoop/Spark开发环境配置

    修改hostname bogon 为localhost 查看ip地址 [training@bogon ~]$ sudo hostname localhost [training@bogon ~]$ h ...

  7. Linux开机启动(bootstrap)上

    Linux开机启动(bootstrap)   作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 计算机开机是一个神秘的过程.我们只是 ...

  8. DCN路由操作

    offset */interface in/out access-list/prefix-list <1-16>                 // 修改路由偏移量   RIP偏移列表 ...

  9. Fragment防止自动清理 (ViewPager滑动时,滑出屏幕后被清理)(转)

    原文链接:http://www.xuebuyuan.com/2231000.html 这个问题网上搜一搜发现帖子很多,但是博主试了几种好像没有说的那么好用 一. 比如给ViewPager设置长度,以增 ...

  10. Python可视化学习(2):Matplotlib快速绘图基础

    Matplotlib将大部分的绘图对象都封装成为对象,故理论上所有的图表元素(如Line2D, Text,Label等)都是对象,都可以将其在图表中提取出来并配置实例的属性.同时,Matplotlib ...