DNA序列 (DNA Consensus String, ACM/ICPC Seoul 2006 UVa1368)
来源:互联网 发布:相机参数详解 知乎 编辑:程序博客网 时间:2024/06/01 21:10
输入m个长度均为n的DNA序列,求一个DNA序列,到所有序列的总Hamming距离尽量小。两个等长字符串的Hamming距离等于字符不同的位置个数,例如,ACGT和GCGA的Hamming距离为2(左数第1, 4个字符不同)。
输入整数m和n(4≤m≤50, 4≤n≤1000),以及m个长度为n的DNA序列(只包含字母A,C,G,T),输出到m个序列的Hamming距离和最小的DNA序列和对应的距离。 如有多解,要求为字典序最小的解。 例如,对于下面5个DNA序列,最优解为TAAGATAC。
TAAGCTACAAAGATCCTGAGATACTAAGATGT
样例:
Input:
3 5 8 TATGATAC TAAGCTAC AAAGATCC TGAGATAC TAAGATGT 4 10 ACGTACGTAC CCGTACGTAG GCGTACGTAT TCGTACGTAA 6 10 ATGTTACCAT AAGTTACGAT AACAAAGCAA AAGTTACCTT AAGTTACCAA TACTTACCAA
Sample Output
TAAGATAC 7 ACGTACGTAA 6 AAGTTACCAA 12
本题目不是很难,就是麻烦点,个人感觉有几个小陷阱,比如遍历字符串矩阵时候先按照列来遍历, 这个小bug我一直没发现,整了很长时间才找到,以后注意了,这里给出原题链接 https://vjudge.net/contest/65968#problem/G 下面给出个人的渣代码.
#include <iostream>using namespace std;char optimal_alpha(int a, int g, int c, int t);char alpha[60][1010];int main(){ int m, n, error, times; cin >> times; while (times--) { error = 0; char result[1010] = { '\0' }; cin >> m >> n; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> alpha[i][j]; } } for (int j = 0; j < n; j++) { int agct_count[200] = { '\0' }; for (int i = 0; i < m; i++) { agct_count[alpha[i][j]]++; } char res_chr = optimal_alpha(agct_count['A'], agct_count['G'], agct_count['C'], agct_count['T']); for (int i = 0; i < m; i++) { if (res_chr != alpha[i][j]) { error++; } } result[j] = res_chr; } cout << result << endl; cout << error << endl; } return 0;}char optimal_alpha(int a, int g, int c, int t){ char agct_char[4] = { 'A', 'G', 'C', 'T' }; int agct_num[4], j = 0; agct_num[0] = a; agct_num[1] = g; agct_num[2] = c; agct_num[3] = t; int max_agct_count = agct_num[0]; char max_alpha = agct_char[0]; for (int i = 1; i < 4; i++) { if (agct_num[i] > max_agct_count) { max_agct_count = agct_num[i]; max_alpha = agct_char[i]; } else if (agct_num[i] == max_agct_count) { if (max_alpha > agct_char[i]) { max_alpha = agct_char[i]; } } } return max_alpha;}
0 0
- DNA序列 (DNA Consensus String, ACM/ICPC Seoul 2006 UVa1368)
- 3-7 DNA序列(DNA Consensus String, ACM/ICPC Seoul 2006, UVa1368)
- DNA Consensus String, ACM/ICPC Seoul 2006, UVa1368
- DNA序列(DNA Consensus String, ACM/ICPC seoul 2006, UVa 1368)
- UVA 1368 DNA Consensus String【ACM/ICPC Seoul 2006】
- UVa1368-DNA Consensus String-DNA序列
- uva1368 - DNA Consensus String
- Uva1368 DNA Consensus String
- Uva1368 - DNA Consensus String
- UVA1368- DNA Consensus String
- UVA1368 - DNA Consensus String
- uva1368 - DNA Consensus String
- uva1368 - DNA Consensus String
- [UVA1368]DNA Consensus String
- UVa1368 DNA Consensus String
- UVa1368 DNA Consensus String
- UVa1368 DNA Consensus String
- UVa1368 - DNA Consensus String
- 欢迎使用CSDN-markdown编辑器
- 2016年总结以及2017年展望(工作技术篇)
- 数码管显示
- display封装
- Java与各种数据库连接代码
- DNA序列 (DNA Consensus String, ACM/ICPC Seoul 2006 UVa1368)
- Learn Python the Hard Way 第四题我就不会了
- STemWin移植到MiCO物联网操作系统笔记-基于秉火STM32F429开发板【2】
- 那些年我们一起饰演的角色
- Codeforces Round #392 (Div. 2) C. Unfair Poll
- php 实现redis发布订阅消息及时通讯
- Linux网络防火墙的简单指令
- Ubutun Linux 使用draw9patch
- 中医经典《伤寒论》-原文