Hamming Distance(随机算法)
http://acm.hdu.edu.cn/showproblem.php?pid=4712
题意:计算任意两个十六进制的数异或后1的最少个数。
思路:用随机数随机产生两个数作为下标,记录这两个数异或后1的个数,输出1的个数最少是多少。
#include <stdio.h>
#include <algorithm>
#include <time.h>
#include <math.h> using namespace std;
const int N=;
const int INF=<<;
int f[N];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,ans = INF;
scanf("%d",&n);
for (int i = ; i < n; i ++)
scanf("%x",&f[i]);
srand((unsigned)time(NULL));
for (int i = ; i < N*; i ++)
{
int a = rand()%n;
int b = rand()%n;
if (a==b)
continue ;
int t = f[a]^f[b];
int temp = __builtin_popcount(t);
ans = min(ans,temp);
}
printf("%d\n",ans);
}
return ;
}
Hamming Distance(随机算法)的更多相关文章
- hdu 4712 Hamming Distance ( 随机算法混过了 )
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- HDU 4712 Hamming Distance(随机算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4712 解题报告:输入n个数,用十六进制的方式输入的,任意选择其中的两个数进行异或,求异或后的数用二进制 ...
- hdu 4712 Hamming Distance 随机
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- HDU 4217 Hamming Distance 随机化水过去
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hdu4712 Hamming Distance
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) To ...
- HDU 4712:Hamming Distance
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- 海明距离hamming distance
仔细阅读ORB的代码,发现有很多细节不是很明白,其中就有用暴力方式测试Keypoints的距离,用的是HammingLUT,上网查了才知道,hamming距离是相差位数.这样就好理解了. 我理解的Ha ...
- hdu 4712 Hamming Distance(随机函数暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
随机推荐
- C# 获取表中最大值
; if (db.LPicture.Any()) { // LPicture Newmode = db.LPicture.Where(n => ).FirstOrDefault(); start ...
- colgroup 整行变色
<table border="2" width="100%"> <colgroup span="2" align=&quo ...
- Oracle query that count connections by minute with start and end times provided
数据结构类似 SQL> select * from t; B E N ----------------- ------------ ...
- 【第8篇】:Python之面向对象
python之--------封装 一.封装: 补充封装: 封装: 体现在两点: 1.数据的封装(将数据封装到对象中) obj = Foo('宝宝',22) 2.封装方法和属性,将一类操作封装到一个类 ...
- [C++] muParser 的简单使用方法
关于 muParser 库 许多应用程序需要解析数学表达式.该库的主要目的是提供一种快速简便的方法. muParser是一个用C ++编写的可扩展的高性能数学表达式解析器库. 它的工作原理是将数学表达 ...
- Django-cookie与session操作
添加cookie: def login(req): if req.method=="POST": uf = UserInfoForm(req.POST) if uf.is_vali ...
- PAT 1110 Complete Binary Tree
Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each in ...
- 手机浏览PC版页面出现背景图片显示不全的问题解决方案
手机浏览PC版页面出现背景图片显示不全 给定宽高的值
- Servlet请求参数编码处理(POST & GET)
小巧,但在中文语境下,还是要注意的. 以下是关键语句,注意转码的先后顺序,这源于GET是HTTP服务器处理,而POST是WEB容器处理: String name = request.getParame ...
- springmvc 中开发Server Send Event
springmvc 中开发Server Send Event 学习了:http://blog.csdn.net/leiliz/article/details/55195203 https://www. ...