HDU - 4712 Hamming Distance(坑爹的随机数算法 + 暴力求解)
来源:互联网 发布:软件小品官网 编辑:程序博客网 时间:2024/06/06 12:50
Hamming Distance
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1728 Accepted Submission(s): 680
Problem Description
(From 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.
Now given N different binary strings, please calculate the minimum Hamming distance between every pair of strings.
Input
The 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".
Output
For each test case, output the minimum Hamming distance between every pair of strings.
Sample Input
2212345543214123456789ABCDEF0137F
Sample Output
67我想对出题的人说一句话,坑爹的题目,坑爹随机算法其中可能提交会出现错误,但是多提交几次就对了(建议大家该为1e6就可以了)#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>#include <cstdio>#include <string>#include <ctime>using namespace std;typedef long long LL;const int MAXN = 1e5 + 5;const int INF = 0x3f3f3f3f;int T, n;int A[MAXN];int Get_Num(int m) { int ret = 0; while(m) { ret += (m & 1); m >>= 1; } return ret;}int main() { scanf("%d", &T); while(T --) { scanf("%d", &n); for(int i = 0; i < n; i ++) { scanf("%X", &A[i]); } srand(time(NULL)); int Min = INF; for(int i = 0; i < 1e5; i ++) { int a = rand() % n; int b = rand() % n; if(a == b) continue; Min = min(Min, Get_Num(A[a] ^ A[b])); } printf("%d\n",Min); } return 0;}
1 0
- HDU - 4712 Hamming Distance(坑爹的随机数算法 + 暴力求解)
- HDU 4712 Hamming Distance [预处理+暴力]
- 暴力或随机-hdu-4712-Hamming Distance
- HDU 4712 Hamming Distance(随机数)
- HDU-4712-Hamming Distance(水随机数)
- HDU 4712 Hamming Distance
- hdu 4712 Hamming Distance
- hdu 4712 Hamming Distance
- hdu 4712 Hamming Distance
- HDU 4712 Hamming Distance
- hdu 4712 Hamming Distance
- hdu 4712 Hamming distance
- HDU 4712 Hamming Distance
- HDU 4712 Hamming Distance
- HDU 4712:Hamming Distance
- HDU 4712 Hamming Distance
- hdu 4712 Hamming Distance
- HDU 472 Hamming Distance (随机数)
- SQL之查询某几行记录--分页查询
- ArcGIS API for Windows phone网站
- javascript--单例模式
- 滤波
- 每个程序员1小时内必须解决的5个编程问题
- HDU - 4712 Hamming Distance(坑爹的随机数算法 + 暴力求解)
- Linux 内核学习之内存寻址(一) 硬件寻址
- Unreal Engine 4 Terminology
- for (int i = 0; gc_handDataOutput->QueryNumberOfHands(); ++i)
- 登录出错不过3,结合springsec
- java使用Xstream注解 解析xml文件 并将数据导入MySql数据库中
- 大数相乘之求N!
- Spring如何实现自动依赖注入-------autowire
- .net/c#得到EXCEL表格中的有效行数和列数