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 ...
随机推荐
- 查看APK包名签名等信息
有些游戏第三方比如分享需要配置游戏包名和签名,不同渠道包名签名又不同,所以时常需要查看不同apk包等签名信息,之前是使用等微博开放平台的手机客户端查看apk签名,前提是知道包名,网上找了下查看签名和包 ...
- Django - 一对多数据示例
1.增加Host -id 可以在模版中增加代码: 备注: 1.counter (从1开始) 2.counter0(从0开始) 3.revcounter(倒序) 4.revcounter0(倒序从0开始 ...
- enote笔记语言(4)
what:我想知道某个“关键词(keyword)”(即,词语,可以是概念|专业术语|.......)的定义. why:我想知道事物发生的原因:我会不会犯“归因错误”?是“单因素”的还是“多因素”的原因 ...
- 取代PHP原生函数的一些扩展包
前言 虽然程序员无时无刻都在造轮子,但造轮子也有效率之分,用好轮子才能造出好"
- BFOA
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> ...
- dubbo服务telnet命令的使用
转自:https://www.cnblogs.com/feiqihang/p/4387330.html dubbo服务发布之后,我们可以利用telnet命令进行调试.管理.Dubbo2.0.5以上版本 ...
- vue 组件通信传值
父子组件通信: 子组件 <template> <div> <h3 @click="alerrt"> 我是子组件一</h3> < ...
- HDU 5442 Favorite Donut
Favorite Donut Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- ubuntu 14.04 gcc/g++版本降低
Matlab 2014a支持的gcc/g++版本是4.7x,而ubuntu 14.04以及更高版本默认安装的版本都是4.8及以上,因此需要降低gcc/g++版本,方法如下: 1 安装 $ sudo a ...
- 华为USG6350防洪墙SNMP最简单功能配置
https://www.cnblogs.com/vincent-liang/p/7785089.html