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 ...
随机推荐
- 细说UI线程和Windows消息队列(经典)
在Windows应用程序中,窗体是由一种称为“UI线程(User Interface Thread)”的特殊类型的线程创建的. 首先,UI线程是一种“线程”,所以它具有一个线程应该具有的所有特征,比如 ...
- 数据结构——栈(Stacks)
栈遵循LIFO ( last in first out) 即后入先出原则 栈结构类似于叠盘子 后叠上去的要先拿走 才能拿到下面的盘子 因此stack是一种访问受限的线性存储结构 用单向链表的结构来存储 ...
- (3)选择元素——(2)文档对象模型(The Document Object Model)
One of the most powerful aspects of jQuery is its ability to make selecting elements in the DOM easy ...
- Surround the Trees(凸包求周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- sublime2/3自总结经常使用快捷键(2的居多)
Ctrl+D 选词 (重复按快捷键,就可以继续向下同一时候选中下一个同样的文本进行同一时候编辑) Ctrl+鼠标左键 能够同一时候选择要编辑的多处文本 Shift+鼠标右键(或使用鼠标中键)能够用鼠标 ...
- server配置学习 ---- 关闭防火墙
iptables 一种网络防火墙,在LINUX下使用,RedHat9.0版本号以上自带. 它能够实现NAT转换.能够做上网代理. 首先对于server的配置第一步来说就是关闭防火墙.在没有图形化中的l ...
- 打印NSLog分类 Foundation+Log.m
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @implementation UIView(Log) + ...
- CMarkUp接口说明
CMarkup是一个小型XML的分析器,实现语言是C++,英文版的接口说明地址为:http://www.firstobject.com/dn_markupmethods.htm 有厉害的网友已经翻译出 ...
- Visual Studio 2012中编写C程序
换了win7系统后,突然发现VC++6.0不兼容了,我听说有的同学的行,反正我是不行. 那就用VS2012呗.... 我们来看看怎么用: 打开文件->新建->项目,新建一个项目 选择win ...
- android 从服务器上获取APK并下载安装
简单的为新手做个分享. 网上有些资料,不过都是很零散,或是很乱的,有的人说看不懂. 一直有新手说 做到服务器更新APK时没有思路,这里做个简单的分享,希望有不同思路的可以讨论. 下 ...