hdu4712 Hamming Distance
Hamming Distance
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1051 Accepted Submission(s): 396
Now given N different binary strings, please calculate the minimum Hamming distance between every pair of strings.
2
12345
54321
4
12345
6789A
BCDEF
0137F
7
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
using namespace std;
#define MAXN 100050
vector<int > vec[23];
int hash[1<<21],pri[MAXN];
char str[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void init()
{
int i;
for(i=0;i<=21;i++)
vec[i].clear();
int ii=1<<21;
for(i=0;i<ii;i++)
{
int ans=0;
for(int j=0;j<21;j++)
{
if(i&(1<<j))ans++;
}
vec[ans].push_back(i);
}
}
int main()
{
init();
int tcase,i,j,k,n;
char str[20],c;
scanf("%d",&tcase);
while(tcase--)
{
memset(hash,0,sizeof(hash));
scanf("%d",&n);
bool flag=true;
for(i=0;i<n;i++)
{
int ans=0;
scanf("%X",&pri[i]);
// printf("%d f\n",pri[i]);
hash[pri[i]]++;
if(flag&&hash[pri[i]]>=2)
flag=false; }
if(!flag)
{
printf("0\n");
continue;
}
for(i=1;i<=20;i++)
{
for(j=0;j<n;j++)
for(k=0;k<vec[i].size();k++)
{
if(hash[pri[j]^vec[i][k]])
{
printf("%d\n",i);
goto my;
}
}
}
my:; }
return 0;
}
hdu4712 Hamming Distance的更多相关文章
- HDU4712 Hamming Distance (随机化)
link:http://acm.hdu.edu.cn/showproblem.php?pid=4712 题意:给1e5个数字,输出这些数中,最小的海明码距离. 思路:距离的范围是0到20.而且每个数的 ...
- [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 ...
- LeetCode:461. Hamming Distance
package BitManipulation; //Question 461. Hamming Distance /* The Hamming distance between two intege ...
随机推荐
- A package manager for Qt
官网 http://www.qpm.io/ A package manager for Qt 注释:这个网站类似JavaScript的包管理器的网站https://www.npmjs.com/ 都是给 ...
- nginx配置ssl加密(单双向认证、部分https)
nginx配置ssl加密(单双向认证.部分https) nginx下配置ssl本来是很简单的,无论是去认证中心买SSL安全证书还是自签署证书,但最近公司OA的一个需求,得以有个机会实际折腾一番.一开始 ...
- extjs 优化小建议
1 原文信息 原文标题: Sencha Con 2013: Ext JS Performance tips 原文地址: [http://edspencer.net/2013/07/19/sencha- ...
- svn恢复到之前某个版本号
一直在找svn回滚的方法,这个还是非常有用的,屡试不爽阿 常常因为坑爹的需求,功能要切回到之前的某一个版本号.有两种方法能够实现: 方法1: 用svn merge 1) 先 svn up,保证更新到 ...
- TCP/IP之DNS域名解析系统
DNS系统是一个分布式的数据库,当一个数据库发现自己并没有某查询所需要的数据的时候,它将把查询转发出去,而转发的目的地通常是根服务器,根服 务器从上至下层层转发查询,直到找到目标为止.DNS还有一个特 ...
- LINQ简单案例
1.在visual studio 创建一个解决方案,新建一个控制台程序Kong 2.新建两个类,分别为Master 类和Kongfu类 Master类中包含成员如下,并重写ToString方法 na ...
- FFT算法
FFT算法的完整DSP实现 傅里叶变换或者FFT的理论参考: [1] http://www.dspguide.com/ch12/2.htm The Scientist and Engineer's G ...
- 从零搭建LNMP环境
Linux就是环境所在的操作系统: Nginx则是一个「高性能的HTTP和反向代理服务器」,官网地址:http://nginx.org/: MySQL则是一个方便地对数据进行增删改查的数据库管理系统, ...
- 互联网创业十问?good(快速迭代、把握核心用户应对抄袭,不需要把商业模式考虑完备,4种失败的信号,失败者没资格说趁着年轻...)
著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:曹政链接:https://www.zhihu.com/question/20264499/answer/28168079来源: ...
- php下载远程图片方法总结(curl手动解析header)curl跳转问题解决
常用方法一般有:. file_get_contents file_put_contents readfile($file) //效率很高. 一般代码: /** * 抓取远程图片 * * @param ...