• 【每日一题】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
    */
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    jenkins api
    打码兔官网 验证码识别 远程答题服务 代答平台 验证码识别软件下载
    WeUI首页、文档和下载
    CMDB, 配置管理数据库, ITIL
    OpenResty Con 2015
    Ngx_lua 最佳技术实践 | UPYUN技术现场
    兔大侠整理的MySQL-Python(MySQLdb)封装类
    58同城沈剑:好的架构源于不停地衍变,而非设计-CSDN.NET
    Lua包管理工具Luarocks详解
    zz
  • 原文地址:https://www.cnblogs.com/SuuT/p/9439031.html
Copyright © 2020-2023  润新知