UVa 3602 - DNA Consensus String 水题 难度: 0

题目

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1603


题意

问使m个n长碱基序列汉明码最小的序列

思路

明显,取最频繁的

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<int, int> MyPair;
int cnt[1000][256];

int main() {
#ifdef LOCAL_DEBUG
    freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
    //freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
    int T;
    int m, n;
    cin >> T;
    for (int ti = 1;cin>>m>>n; ti++) {
        string tmp;
        memset(cnt, 0, sizeof cnt);
        for (int i = 0; i < m; i++) {
            cin >> tmp;
            for (int j = 0; j < n; j++) {
                cnt[j][tmp[j]]++;
            }
        }
        int ans = 0;
        for (int j = 0; j < n; j++) {
            char anschar = 'A';
            for (char ch : {'A', 'C', 'G', 'T'}) {
                if (cnt[j][ch] > cnt[j][anschar]) {
                    anschar = ch;
                }
            }
            putchar(anschar);
            ans += m - cnt[j][anschar];
        }
        putchar('\n');
        printf("%d\n", ans);
    }

    return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/xuesu/p/10462837.html