Find a sequence with the smallest total Hamming distance from the given sequence, and the smallest solution of the output dictionary order
Hamming distance is two different characters with several positions in a sequence
1#include <iostream>2 using namespacestd;3 intT,n,m,ans1,cnt,tmp1,tmp2,tmp3,tmp4;4 Chars[ -][1005],ans2[1005];5 voidjudge ()6 {7 if(tmp1>=tmp2&&tmp1>=tmp3&&tmp1>=tmp4)8 {9ans2[cnt++]='A';Tenans1+=tmp2+tmp3+Tmp4; One } A Else if(tmp2>=tmp1&&tmp2>=tmp3&&tmp2>=tmp4) - { -ans2[cnt++]='C'; theans1+=tmp1+tmp3+Tmp4; - } - Else if(tmp3>=tmp2&&tmp3>=tmp1&&tmp3>=tmp4) - { +ans2[cnt++]='G'; -ans1+=tmp1+tmp2+Tmp4; + } A Else at { -ans2[cnt++]='T'; -ans1+=tmp1+tmp2+Tmp3; - } - } - voidfuc () in { -Ans1=cnt=0; to for(intj=0; j<m;j++) + { -tmp1=tmp2=tmp3=tmp4=0; the for(intI=0; i<n;i++) * { $ Switch(S[i][j])Panax Notoginseng { - Case 'A': tmp1++; Break; the Case 'C': tmp2++; Break; + Case 'G': tmp3++; Break; A Case 'T': tmp4++; Break; the } + } - judge (); $ } $ans2[cnt]=' /'; - } - intMain () the { -Cin>>T;Wuyi while(t--) the { -Cin>>n>>m; Wu for(intI=0; i<n;i++) cin>>S[i]; - fuc (); Aboutcout<<ans2<<Endl; $cout<<ans1<<Endl; - } -}
UVa 1368-dna Consensus String