UVA - 1368 DNA Consensus String
生活随笔
收集整理的這篇文章主要介紹了
UVA - 1368 DNA Consensus String
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
DNA Consensus String
?UVA - 1368?
題目傳送門
解決方法:尋找每列中出現最多的字母。
AC代碼
#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <map> #include <stack> #include <queue> #include <vector> #include <bitset> #include <set> #include <utility> #include <sstream> #include <iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; #define inf 0x3f3f3f3f #define rep(i,l,r) for(int i=l;i<=r;i++) #define lep(i,l,r) for(int i=l;i>=r;i--) #define ms(arr) memset(arr,0,sizeof(arr)) //priority_queue<int,vector<int> ,greater<int> >q; const int maxn = (int)1e5 + 5; const ll mod = 1e9+7; char mapp[55][1050]; char arr[1200]; map<char,int> mt; int main() {#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int T;scanf("%d",&T);while(T--){int n,m;ms(arr);scanf("%d %d",&n,&m);rep(i,1,n) {scanf("%s",mapp[i]+1);}int ans=0;rep(j,1,m) {int maxl=0;for(char t='A';t<='Z';t++)mt[t]=0; rep(i,1,n) {mt[mapp[i][j]]++;}for(char t='A';t<='Z';t++){if(mt[t]>maxl){arr[j]=t;maxl=mt[t];}ans+=mt[t];}ans-=maxl;}rep(j,1,m) {printf("%c",arr[j]);}printf("\n");printf("%d\n",ans);}return 0; }?
總結
以上是生活随笔為你收集整理的UVA - 1368 DNA Consensus String的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Frequent values【线段树】
- 下一篇: Problem D: 删出多余的空格