hdu 4712 Hamming Distance(随机函数暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=4712
Hamming Distance
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 797 Accepted Submission(s): 284
Now given N different binary strings, please calculate the minimum Hamming distance between every pair of strings.
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <time.h> using namespace std;
#define N 100000 char str[N+][];
int mark[][]; //make中存 i^j 的1的个数
int arr[]={,,,,,,,,,,,,,,,}; //0-F 中1的个数 int charToHex(char ch) //将0-F字符转换成10进制数计算
{
if(isdigit(ch)) return ch-'';
return ch-'A'+;
} void getMark() //求mark数组
{
int i,j,s;
for(i=;i<;i++)
{
for(j=i;j<;j++)
{
s=i^j;
mark[i][j]=mark[j][i]=arr[s];
}
}
} int geths(int x,int y) //求x到y的Hamming distance
{
int i,sum=;
for(i=;i<;i++)
{
int xx = charToHex(str[x][i]);
int yy = charToHex(str[y][i]);
sum+=mark[xx][yy];
}
return sum;
} int main()
{
int t;
getMark();
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int i;
for(i=;i<n;i++)
{
scanf("%s",str[i]);
}
srand(time(NULL));
int x,y,mins=;
for(i=;i<;i++) //随机900000次基本能过,在不超时的前提下,随机次数越多越好
{
x=rand()%n;
y=rand()%n;
if(x==y) continue;
int temp = geths(x,y);
if(mins>temp) mins=temp;
}
printf("%d\n",mins);
}
return ;
}
/*
2
2
12345
54321
4
12345
6789A
BCDEF
0137F
*/
hdu 4712 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 ( 随机算法混过了 )
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 题目大意:任意两个数按位异或后二进制中含1的个数被称为海明距离,给定n个数,求出任意其中两个最小 ...
- HDU 4712 Hamming Distance(随机算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4712 解题报告:输入n个数,用十六进制的方式输入的,任意选择其中的两个数进行异或,求异或后的数用二进制 ...
- hdu 4712 Hamming Distance(随机数法)
d.汉明距离是使用在数据传输差错控制编码里面的,汉明距离是一个概念,它表示两个(相同长度)字对应位不同的数量, 我们以d(x,y)表示两个字x,y之间的汉明距离.对两个字符串进行异或运算,并统计结果为 ...
- hdu 4712 Hamming Distance bfs
我的做法,多次宽搜,因为后面的搜索扩展的节点会比较少,所以复杂度还是不需要太悲观的,然后加上一开始对答案的估计,用估计值来剪枝,就可以ac了. #include <iostream> #i ...
- 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) ...
随机推荐
- MJViewController的view的创建
- Linux 命令 - cat: 合并文件至标准输出
命令格式 cat [OPTION]... [FILE]... 命令参数 -A, --show-all 等价于 -vET. -b, --number-nonblank 对非空输出行编号. -e 等价于 ...
- Java Servlet-http协议
---恢复内容开始--- 互联网三大基石: url:定位数据 html:显示数据 http:传输数据
- JS判断移动设备最佳方法
最实用的还是下面这个: 方法一:纯JS判断 使用这方法既简单,又实用,不需要引入jQuery库,把以下代码加入到<head>里即可. <script type=”text/javas ...
- 【leetcode】4. Median of Two Sorted Arrays
题目描述: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of t ...
- 为oracle中的表格增加列和删除列
http://blog.csdn.net/rainharder/article/details/6663458 alter table 表名 drop column 列名eg:alter table ...
- 基数排序(RadixSort)
1 基数排序的特点是研究多个关键字key,且多个key之间有权重之分, 或者可把单个key建模为含有多个key的排序 而计数排序.桶排序始终只有个一个key,或者说围绕着一个比较规则 Ex:比较 ...
- 关联 Android 源代码 到 Ecplise
1. 下载android 源码存于本地硬盘; 2. 打开Eclpise, 新建Android Project; 3. 在MainActivity文件中,按住Ctrl 点击Activity类 4. 弹出 ...
- jQuery自己编写插件()
引言: 在项目中不同页面经常要用到已经写好的交互,比如弹窗,比如下拉菜单,比如选项卡,比如删除... 此时如果每次都把代码copy一份无疑是一件比较麻烦并且无趣的事情,而且个人认为有些low了,我们可 ...
- 利用cglib生成动态java bean
cglib详细学习 http://blog.csdn.net/u010150082/article/details/10901641 cglib-nodep jar报下载 http://grepcod ...