HDU 4217 Hamming Distance 随机化水过去
Hamming Distance
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1569 Accepted Submission(s): 616
wikipedia) For binary strings a and b the Hamming distance is equal to
the number of ones in a XOR b. For calculating Hamming distance between
two strings a and b, they must have equal length.
Now given N different binary strings, please calculate the minimum Hamming distance between every pair of strings.
first line of the input is an integer T, the number of test
cases.(0<T<=20) Then T test case followed. The first line of each
test case is an integer N (2<=N<=100000), the number of different
binary strings. Then N lines followed, each of the next N line 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
12345
54321
4
12345
6789A
BCDEF
0137F
7
- #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 4217 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 解题报告:输入n个数,用十六进制的方式输入的,任意选择其中的两个数进行异或,求异或后的数用二进制 ...
- hdu 4712 Hamming Distance(随机函数暴力)
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 4712 Hamming Distance(随机算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4712 题目大意:任意两个数按位异或后二进制中含1的个数被称为海明距离,给定n个数,求出任意其中两个最小 ...
- Hamming Distance(随机算法)
http://acm.hdu.edu.cn/showproblem.php?pid=4712 题意:计算任意两个十六进制的数异或后1的最少个数. 思路:用随机数随机产生两个数作为下标,记录这两个数异或 ...
- hdu 4712 Hamming Distance(随机数法)
d.汉明距离是使用在数据传输差错控制编码里面的,汉明距离是一个概念,它表示两个(相同长度)字对应位不同的数量, 我们以d(x,y)表示两个字x,y之间的汉明距离.对两个字符串进行异或运算,并统计结果为 ...
- hdu 4712 Hamming Distance bfs
我的做法,多次宽搜,因为后面的搜索扩展的节点会比较少,所以复杂度还是不需要太悲观的,然后加上一开始对答案的估计,用估计值来剪枝,就可以ac了. #include <iostream> #i ...
随机推荐
- URIEncoding与useBodyEncodingForURI 在tomcat中文乱码处理上的区别
大家知道tomcat5.0开始,对网页的中文字符的post或者get,经常会出现乱码现象. 具体是因为Tomcat默认是按ISO-8859-1进行URL解码,ISO-8859-1并未包括中文字符,这样 ...
- c++字节数组转换为整型
http://bbs.csdn.net/topics/360132089 BYTE data[4]={0x00,0x00,0xe6,0x00};//第一句UINT a11=*(UINT*)data;/ ...
- spring boot jpa 多数据源配置
在实际项目中往往会使用2个数据源,这个时候就需要做额外的配置了.下面的配置在2.0.1.RELEASE 测试通过 1.配置文件 配置两个数据源 spring.datasource.url=jdbc:m ...
- 栈应用之 后缀表达式计算 (python 版)
栈应用之 后缀表达式计算 (python 版) 后缀表达式特别适合计算机处理 1. 中缀表达式.前缀表达式.后缀表达式区别 中缀表达式:(3 - 5) * (6 + 17 * 4) / 3 17 ...
- UFLDL 教程学习笔记(二)
课程链接:http://ufldl.stanford.edu/tutorial/supervised/LogisticRegression/ 这一节主要讲的是梯度的概念,在实验部分,比较之前的线性回归 ...
- dpr 与 dproj 有什么区别
- sql server 2005/2008R2 报“红叉”错,即“不允许所请求的注册表访问权”的错误
一.使用报错展示: 1.红叉错: 2.报错文字信息: 解决办法:可以鼠标右键,以管理员的身份运行即可,但这治标不治本,按如下方法可以彻底解决:把“以管理员身份运行此程序”勾上,即可
- Rewrite HTTP to HTTPS in Nginx
1.推荐配置 server { listen 80; server_name example1.com example2.com; return 301 https://$host$request_u ...
- hdu 5078(2014鞍山现场赛 I题)
数据 表示每次到达某个位置的坐标和时间 计算出每对相邻点之间转移的速度(两点间距离距离/相隔时间) 输出最大值 Sample Input252 1 9//t x y3 7 25 9 06 6 37 6 ...
- Rookey.Frame之数据库及缓存配置
上一篇中讨论了Rookey.Frame框架菜单配置功能,这一节我们继续学习Rookey.Frame框架的数据库连接配置. 之前介绍了Rookey.Frame框架支持跨多数据库,并且支持读写分离,不过目 ...