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. apache 配置多个版本的 php

    注:这里说的是windows环境下的配置 我们在配置apache+php的时候,是在apache的配置文件httpd.conf里加载php的模块并指定php.ini路径 LoadModule php5 ...

  2. 找回mysql数据库root用户的密码

  3. 配置uwsgi

    首先要明确的是,如果你喜欢用命令行的方式(如shell)敲命令,那可以省去任何配置. 但是,绝大多数人,还是不愿意记那么长的命令,反复敲的.所以uwsgi里,就给大家提供了多种配置,省去你启动时候,需 ...

  4. 关于Android开发的几点建议

    绝不要在UI线程中做数据处理的工作,这会让你的app变慢,带来极差的用户体验. 要按照google发布的Design指导意见来设计app,比如一个holo主题app会给用户带来更好的用户体验. 不要复 ...

  5. Node.js服务端框架谁才是你的真爱

    1. Express 背景: Express, 疯一般快速(而简洁)的服务端JavaScript Web开发框架,基于Node.js和V8 JavaScript引擎. Express 是一个基于 No ...

  6. 大数据时代日志分析平台ELK的搭建

    A,首先说说ELK是啥,  ELK是ElasticSearch . Logstash 和 Kiabana 三个开源工具组成.Logstash是数据源,ElasticSearch是分析数据的,Kiaba ...

  7. go单元测试进阶篇

    作者介绍:熊训德(英文名:Sundy),16年毕业于四川大学大学并加入腾讯.目前在腾讯云从事hadoop生态相关的云存储和计算等后台开发,喜欢并专注于研究大数据.虚拟化和人工智能等相关技术. 本文档说 ...

  8. 前端总结·基础篇·JS(四)异步请求及跨域方案

    前端总结系列 前端总结·基础篇·CSS(一)布局 前端总结·基础篇·CSS(二)视觉 前端总结·基础篇·CSS(三)补充 前端总结·基础篇·JS(一)原型.原型链.构造函数和字符串(String) 前 ...

  9. smokeping安装部署最佳实践

    1.1安装smokeping [root@linux-node2 ~]# cat /etc/redhat-release              #查看服务器信息 CentOS release 6. ...

  10. [原]C#与非托管——初体验

    P/Invokes初看起来非常简单,利用DllImport进行extern函数的声明,程序就可以在调用extern函数的时候自动查询调用到对应的非托管函数,有些类似Java的native函数,但更为简 ...