HDU4712 Hamming Distance (随机化)
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 (随机化)相关推荐
- Leetcode 461. Hamming Distance JAVA语言
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- [LeetCode] 461. Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- C++ hamming distance汉明距离算法(附完整源码)
hamming distance汉明距离的算法 hamming distance汉明距离的算法的完整源码(定义,实现,main函数测试) hamming distance汉明距离的算法的完整源码(定义 ...
- LeetCode 461 Hamming Distance(汉明距离)
Q:The Hamming distance between two integers is the number of positions at which the corresponding bi ...
- LeetCode之Hamming Distance
1.题目 The Hamming distance between two integers is the number of positions at which the corresponding ...
- 461. Hamming Distance【数学|位运算】
2017/3/14 15:23:55 The Hamming distance between two integers is the number of positions at which the ...
- LeetCode 461. Hamming Distance
题目: The Hamming distance between two integers is the number of positions at which the corresponding ...
- C#LeetCode刷题之#461-汉明距离(Hamming Distance)
问题 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目. 给出两个整数 x 和 y,计算它们之间的汉明距离. 注意:0 ≤ x, y < 231. 输入: x = 1, y = ...
- 【LeetCode】461. Hamming Distance (java实现)
2019独角兽企业重金招聘Python工程师标准>>> 原题链接 https://leetcode.com/problems/hamming-distance/ 原题 The Ham ...
最新文章
- C++中explicit关键字的作用
- 百度智能小程序正式开源,开发方案详解
- 使用Identity Server 4建立Authorization Server (6) - js(angular5) 客户端
- mysql不同的类的个数_Mysql数据库-SQL优化-统计某种类型的个数
- 这是一篇测试博文的文章
- 华中科技大学2005年计算机组成原理试题,华中科技大学200年计算机组成原理考研试题.doc...
- nginx开机启动脚本
- 黑客(一):黑客守则
- 华为手机怎样才算激活了_华为手机激活是怎么回事
- 超强数据恢复软件【含注册码】
- 雅思考试流程、需要具体注意些什么、怎么复习?
- openwrt的ipk包开发
- JavaScript设计模式之“单例模式“
- web表格制作--11.27
- 大学python教材实验七字典与集合答案_Python中的字典与集合
- 国内jQuery CDN
- windows下延时函数
- python 自动上色_Github | 线稿自动上色
- 使用Adobe Illustrator将EPS编辑为合适的论文图片
- Vivado 2019.1安装包下载