zoukankan      html  css  js  c++  java
  • 【每日一题】UVA

    https://cn.vjudge.net/problem/UVA-1368

    二维的hamming距离算法:

    For binary strings a and b the Hamming distance is equal to the number of ones (population count) in a XOR b.

    int hamming_distance(unsigned x, unsigned y)
    {
        int dist = 0;
        unsigned  val = x ^ y;
    
        // Count the number of bits set
        while (val != 0)
        {
            // A bit is set, so increment the count and clear the bit
            dist++;
            val &= val - 1;
        }
    
        // Return the number of differing bits
        return dist;
    }

    Two example distances: 100→011has distance 3; 010→111 has distance 2

    以上是题外话,

    其实二进制hamming距离和这题无关啦,就是一个暴力算hamming距离,然后贪心地找

    坑点:for(i,0,len)写错,应该是len-1,很难debug出来

    orz 我先用set,然后发现还是要重载运算符orz 最后map暴力,还不如数组呢

    #define _CRT_SECURE_NO_WARNINGS
    #include<cmath>
    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<cstring>
    #include<stack>
    #include<vector>
    #include<string.h>
    #include<queue>
    #include<string>
    #include<set>
    #include<map>
    using namespace std;
    typedef long long ll;
    #define mod 1000000007
    #define rep(i,t,n)  for(int i =(t);i<=(n);++i)
    #define per(i,n,t)  for(int i =(n);i>=(t);--i)
    #define mmm(a,b) memset(a,b,sizeof(a))
    #define eps 1e-6
    #define pb push_back
    #define mp make_pair
    #define x first
    #define y second
    const int maxn = 55;
    ll n,m;
    
    string s[maxn];
    map<char, int> mmp;
    
    int main()
    {
    
        int t; cin >> t;
        while (t--) {
            cin >> n >> m;
            rep(i, 1, n)cin >> s[i];
            string ans ; ans.clear();
            int now = 0, mn = 0;
            rep(j, 0, m-1) {
                
                mmp.clear();
                rep(i, 1, n) {
                    //cnt[s[i][j]]++;
                    mmp[s[i][j]]++;
    
                }
                pair<char, int> temp = { 'Z',-1 };
                for (auto t : mmp)if (t.second > temp.second|| (t.second == temp.second&&t.first<temp.first))temp = t; 
                ans.push_back(temp.first);
                mn += n -temp.second;
    
            }
            cout << ans << endl;
            cout << mn << endl;
        }
    
    
        
        cin >> n;
        return 0;
    }
    /*
    3
    5 8
    TATGATAC
    TAAGCTAC
    AAAGATCC
    TGAGATAC
    TAAGATGT
    4 10
    ACGTACGTAC
    CCGTACGTAG
    GCGTACGTAT
    TCGTACGTAA
    6 10
    ATGTTACCAT
    AAGTTACGAT
    AACAAAGCAA
    AAGTTACCTT
    AAGTTACCAA
    TACTTACCAA
    */
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    $.getJSON异步请求和同步请求
    Jquery中click事件重复执行的问题
    明白JavaScript原型链和JavaScrip继承
    利用canvas对上传图片进行上传前压缩
    webpack打包多html开发案例
    移动端的picker参考vux
    Vue于React特性简单对比(一)
    移动端调试和fiddler移动端抓包使用
    开发过程中的关键思维方法
    js移动端滑块验证解锁组件
  • 原文地址:https://www.cnblogs.com/SuuT/p/9439031.html
Copyright © 2011-2022 走看看