HDU 4712:Hamming Distance
Hamming Distance
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1845 Accepted Submission(s): 740
Now given N different binary strings, please calculate the minimum Hamming distance between every pair of strings.
is a string consist of five characters. Each character is '0'-'9' or 'A'-'F', it represents the hexadecimal code of the binary string. For example, the hexadecimal code "12345" represents binary string "00010010001101000101".
2 2 12345 54321 4 12345 6789A BCDEF 0137F
6 7
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
题意:给出n个字符串,求每两个串相应位异或值的二进制中1的个数和的最小值!
例如:
12345
54321
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <time.h>
using namespace std;
int cmp[16][16]= {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,0,2,1,2,1,3,2,2,1,3,2,3,2,4,3,1,2,0,1,2,3,1,2,2,3,1,2,3,4,2,3,2,1,1,0,3,2,2,1,3,2,2,1,4,3,3,2,1,2,2,3,0,1,1,2,2,3,3,4,1,2,2,3,2,1,3,2,1,0,2,1,3,2,4,3,2,1,3,2,2,3,1,2,1,2,0,1,3,4,2,3,2,3,1,2,3,2,2,1,2,1,1,0,4,3,3,2,3,2,2,1,1,2,2,3,2,3,3,4,0,1,1,2,1,2,2,3,2,1,3,2,3,2,4,3,1,0,2,1,2,1,3,2,2,3,1,2,3,4,2,3,1,2,0,1,2,3,1,2,3,2,2,1,4,3,3,2,2,1,1,0,3,2,2,1,2,3,3,4,1,2,2,3,1,2,2,3,0,1,1,2,3,2,4,3,2,1,3,2,2,1,3,2,1,0,2,1,3,4,2,3,2,3,1,2,2,3,1,2,1,2,0,1,4,3,3,2,3,2,2,1,3,2,2,1,2,1,1,0};;
char p[1000005][10];
int ddd(int q,int w)
{
int a,b,s=0;
for(int i=0; i<5; i++)
{
char x = p[q][i];
char y = p[w][i];
if(isdigit(x))a=x-'0';
else a=x-'A'+10;
if(isdigit(y))b=y-'0';
else b=y-'A'+10;
s += cmp[a][b];
}
return s;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int N;
cin>>N;
int minn=0xfffffff;
for(int i=0; i<N; i++)
cin>>p[i];
srand((unsigned)time(NULL));
for(int i=1; i<=100000; i++)
{
int a=rand()%N;
int b=rand()%N;
if(a==b)continue;
int tmp=ddd(a,b);
minn=tmp>minn?minn:tmp;
}
cout<<minn<<endl;
}
return 0;
}
HDU 4712:Hamming Distance的更多相关文章
- [LeetCode] Total Hamming Distance 全部汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- [LeetCode] 477. Total Hamming Distance 全部汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- 使用jax加速Hamming Distance的计算
技术背景 一般认为Jax是谷歌为了取代TensorFlow而推出的一款全新的端到端可微的框架,但是Jax同时也集成了绝大部分的numpy函数,这就使得我们可以更加简便的从numpy的计算习惯中切换到G ...
- hdu 4712 Hamming Distance(随机函数暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hdu 4712 Hamming Distance 随机
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- hdu 4712 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 ...
- HDU 472 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) ...
随机推荐
- kfed (kernel file editor:内核文件编辑器)
kfed是没有在文档中标出的asm工具,在oracle 11gR1中被引入.可以被用来读写asm元数据,特别是磁盘头和asm元数据的内容. kfed是一个单独的工具,不依赖与asm实例,所以可以对mo ...
- nodejs发起HTTPS请求并获取数据
摘要:在网站中有时候需要跨域请求数据,直接用Ajax无法实现跨域,采用其他方式需要根据不同的浏览器做相应的处理.用Nodejs可以很好的解决这些问题,后台引用HTTPS模块,发送和返回的数据均为JSO ...
- 学习OpenCV——鼠标事件(画框)
#include "cv.h" #include "highgui.h" bool check_line_state=false; IplImage* work ...
- 3D照片放大展示窗口
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- HTML中调用servlet的问题(?)
最近在学习servlet.刚开始时,按照案例一行一行的敲代码.不过,出问题了. hello1.html <!DOCTYPE html> <html> <head> ...
- manacher 最长回文子串
确定当前已知能匹配到的最长处,看是否要更新最长 #include <bits/stdc++.h> using namespace std; const int N = 210005; in ...
- fzu 2146 Easy Game
http://acm.fzu.edu.cn/problem.php?pid=2146 Problem 2146 Easy Game Accept: 661 Submit: 915Time Li ...
- gson使用注意事项
public static Object toBean(String jsonString, Class<?> beanclass) { GsonBuilder gsonb = new G ...
- 在Tomcat里使用配置连接池连接数据库
一:首先在Tomcat下的conf/context.xml文件里的contenx标签里配置数据源: <Resource name="jdbc/zzz" auth=" ...
- paper 10:支持向量机系列七:Kernel II —— 核方法的一些理论补充,关于 Reproducing Kernel Hilbert Space 和 Representer Theorem 的简介。
在之前我们介绍了如何用 Kernel 方法来将线性 SVM 进行推广以使其能够处理非线性的情况,那里用到的方法就是通过一个非线性映射 ϕ(⋅) 将原始数据进行映射,使得原来的非线性问题在映射之后的空间 ...