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) ...
随机推荐
- (Factory method)工厂方法设计模式
定义: 1.) 工厂方法模式是用来封装对象的创建,通过让子类来决定创建的对象是什么,来达到将对象创建的过程封装的目的: 2.) 定义了一个创建对象的接口,但由子类决定要实例的泪是哪一个.工厂方法让类把 ...
- PostgreSQL Replication之第十二章 与Postgres-XC一起工作(4)
12.4 性能优化 Postgres-XC不是一个奇特的PostgreSQL版本,而是一个真正的分布式系统.这意味这,您不能只存储数据,希望事情超出服务器之外的快速,高效.如果您想优化速度,思考数据是 ...
- __int64和long long输入输出
__int64 num; scanf("%I64d", &num); printf("%I64d\n", num); long long num; sc ...
- 01分数规划zoj2676(最优比例,最小割集+二分)
ZOJ Problem Set - 2676 Network Wars Time Limit: 5 Seconds Memory Limit: 32768 KB S ...
- ASPNET服务端控件练习(一个机试题)
简单记录: 模糊查询的select语句的拼写 public List<Model.Student> GetWhereStudent(string name, string sub, str ...
- 20145207《Java程序设计》第9周学习总结
教材学习内容总结 第十六章 整合数据库 JDBC是用于执行SQL的解决方案,开发人员使用JDBC的标准接口,数据库厂商则对接口进行操作,开发人员无须接触底层数据库驱动程序的差异性.厂商在操作JDBC驱 ...
- Array.prototype.each
Array.prototype.each = function(closure){ //递归合并 return this.length ? [closure(this.slice(0,1))].con ...
- php laravel curD
Laravel PHP Web开发框架 Laravel是一套简洁.优雅的PHP Web开发框架(PHP Web Framework).它可以让你从面条一样杂乱的代码中解脱出来:它可以帮你构建一个完美的 ...
- [Ubuntu] Remove Byte Order Mark (BOM) from files recursively [Forward article]
Original article: http://www.yiiframework.com/wiki/570/remove-byte-order-mark-bom-from-files-recursi ...
- Azure Deploy
http://msdn.microsoft.com/en-us/library/dn408531.aspx https://www.windowsazure.com/en-us/documentati ...