HDU 4712 Hamming Distance (random number method)

Source: Internet
Author: User

D. Hamming distance is used in the data transmission error control code inside, Hamming distance is a concept, it represents two (the same length) word corresponds to the number of different digits,

We use D (x, y) to denote the Hamming distance between two characters and X, Y. The number of two strings is different or operation, and the statistic result is 1, then this is the Hamming distance.

The minimum Hamming distance (the Hamming distance of some 2 strings is the smallest) is obtained by giving N strings.

S. Random number method ...

C. Can you live, look at the face ...

#include <iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<time.h>using namespacestd;intMain () {//cout<<rand_max<<endl;//32767    intT; intN; Charstr[100005][Ten]; intnum[100005]; inti; intJ; intmi; intfuck; intshit; inttmp; intsum; scanf ("%d",&T);  while(t--) {scanf ("%d",&N);  for(i=0; i<n;++i) {scanf ("%s", Str[i]); } memset (num,0,sizeof(num));  for(i=0; i<n;++i) {             for(j=0;j<5;++j) {                if('0'<=str[i][j]&&str[i][j]<='9') {Num[i]= (num[i]<<4) + (str[i][j]-'0'); }                Else{Num[i]= (num[i]<<4)+(Ten+str[i][j]-'A'); }}} mi= +;        Srand (Time (NULL));  for(i=0;i<400005;++i) {Fuck= (rand () *rand ())%N;//This is a look-face code ... Shit= (rand () *rand ())%N; if(fuck==shit) {                Continue; } tmp=num[fuck]^Num[shit]; Sum=0;  while(tmp>0) {sum=sum+ (tmp&1); TMP>>=1; }            if(sum<mi) {mi=sum; }} printf ("%d\n", MI); }    return 0;}
View Code

HDU 4712 Hamming Distance (random number method)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.