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);
}
}
HDU4712 Hamming Distance (随机化)的更多相关文章
- hdu4712 Hamming Distance
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) To ...
- HDU 4217 Hamming Distance 随机化水过去
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- [LeetCode] Total Hamming Distance 全部汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- [LeetCode] Hamming Distance 汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- Total Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- 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 ...
- LeetCode Total Hamming Distance
原题链接在这里:https://leetcode.com/problems/total-hamming-distance/ 题目: The Hamming distance between two i ...
- LeetCode Hamming Distance
原题链接在这里:https://leetcode.com/problems/hamming-distance/ 题目: The Hamming distance between two integer ...
随机推荐
- Linux下文件误删除恢复案例
说明:将/etc/profile文件删除,然后恢复 在linux中为什么讲文件删除还能恢复呢? 详见:文件删除原理 http://blog.csdn.net/grantlee1988/article/ ...
- MYSQL数据库-其他
FROM:实验楼 索引: 当表中有大量记录时,若要对表进行查询,没有索引的情况是全表搜索.而如果在表中已建立索引,在索引中找到符合查询条件的索引值,通过索引值就可以快速找到表中的数据. 建立索引: $ ...
- java集合体系
Collection接口: 1.单列集合类的根接口. 2.定义了可用于操作List.Set的方法--增删改查: 3.继承自Iterable<E>接口,该接口中提供了iterator() 方 ...
- 使用Python对Access读写操作
学习Python的过程中,我们会遇到Access的读写问题,这时我们可以利用win32.client模块的COM组件访问功能,通过ADODB操作Access的文件. 1.导入模块 import win ...
- JDBC连接Oracle数据库代码
import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.S ...
- oracle物理视图(转)
近期根据项目业务需要对oracle的物化视图有所接触,在网上搜寻关于这方面的资料,便于提高,整理内容如下: 物化视图是一种特殊的物理表,“物化”(Materialized)视图是相对普通视图而言的.普 ...
- SPOJ-ANTP [组合数学]
tags:[组合][预处理]题解:关于方程A+C+B=X的正整数解组数.我们用插板法可知,解的组数=在(X-1)个元素中选择两个元素的方案数故答案为:C(x-1,2)+C(x,2)+C(x+1,2)+ ...
- 创建你的第一个webdriver python代码
前言 今天我们开始我们的第一个python webdriver自动化测试脚本.并就测试脚本进行一一解释说明. webdriver python代码 本示例代码演示了使用Ie浏览器访问百度进行搜索测试. ...
- lumen 中的 .env 配置文件简介和适用场景
lumen 是 laravel 的衍生品,核心功能的使用和 laravel 都是一致的,但配置文件这一方面,lumen 在 laravel 的基础上增加了更简便的配置方式: lumen 采用了 Dot ...
- JavaWeb项目实现文件上传动态显示进度
很久没有更新博客了,这段时间实在的忙的不可开交,项目马上就要上线了,要修补的东西太多了.当我在学习JavaWeb文件上传的时候,我就一直有一个疑问,网站上那些博客的图片是怎么上传的,因为当提交了表单之 ...