DNA Consensus String UVA - 1368

Posted 033000-

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DNA Consensus String UVA - 1368相关的知识,希望对你有一定的参考价值。

题意见紫书

当有多解的时候输出字典序最小的

每一位都是互相独立的,所以每一位只要输出出现次数最多的字母,如果有多个相同的输出字典序最小的就行了

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<assert.h>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<sstream>
#include<stack>
#include<queue>
#include<string>
#include<bitset>
#include<algorithm>
using namespace std;
#define me(s)  memset(s,0,sizeof(s))
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define Di(x) int x;scanf("%d",&x)
#define in(x) inp(x)
#define in2(x,y) inp(x),inp(y)
#define in3(x,y,z) inp(x),inp(y),inp(z)
#define ins(x) scanf("%s",x)
#define ind(x) scanf("%lf",&x)
#define IO ios_base::sync_with_stdio(0);cin.tie(0)
#define READ freopen("C:/Users/ASUS/Desktop/in.txt","r",stdin)
#define WRITE freopen("C:/Users/ASUS/Desktop/out.txt","w",stdout)
template<class T> void inp(T &x) {//读入优化
	char c = getchar(); x = 0;
	for (; (c < 48 || c>57); c = getchar());
	for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; }
}
typedef pair <int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-15;

const int maxn =2000 + 5;

int cnt[maxn][4];
map<char, int> Mp = { { ‘A‘,0 },{ ‘C‘,1 },{ ‘G‘,2 },{ ‘T‘,3 } };
map<int, char> Mp_ = { { 0,‘A‘ },{ 1,‘C‘ },{ 2,‘G‘ },{ 3,‘T‘ } };
int main() {
	//READ;
	//WRITE;
	Di(T);
	while (T--) {
		int n, m;
		in2(n, m);
		me(cnt);
		_for(i, 0, n) {
			string s;
			cin >> s;
			_for(j, 0, m)
				cnt[j][Mp[s[j]]]++;
		}
		int ans = 0;
		_for(i, 0, m) {
			int Max = max(max(cnt[i][0], cnt[i][1]), max(cnt[i][2], cnt[i][3]));
			_for(j,0,4)
				if (cnt[i][j] == Max) {
					putchar(Mp_[j]);
					break;
				}
			ans += n - Max;
		}
		puts("");
		printf("%d
", ans);
	}

}

  

 

以上是关于DNA Consensus String UVA - 1368的主要内容,如果未能解决你的问题,请参考以下文章

DNA Consensus String,( UVa, 1368 )

DNA Consensus String UVA - 1368

UVA-1368 DNA Consensus String (贪心)

DNA序列(DNA Consensus String)

DNA序列(DNA Consensus String)

LA 3602 DNA Consensus String (暴力枚举)