DNA Consensus String,( UVa, 1368 )

题目链接 :https://vjudge.net/problem/UVA-1368

题目首先得知道什么是Hamming距离(自行查找),然后注意出现多个解是选择字典序小者(直接将字典序排号比较),**注意数组大小。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define maxn 1000
 4 #define maxm 1000
 5
 6 char DNA[maxn][maxm];
 7 int main()
 8 {
 9     int N;
10     scanf("%d",&N);
11     while(N--)
12     {
13         int n,m,list[4],num1 = 0,num = 0;
14         scanf("%d %d",&n,&m);
15         for (int i = 0;i < n;i++)
16             scanf("%s",DNA[i]);
17         for(int i = 0;i < m;i++ ){
18             memset(list,0,sizeof(list));
19             for (int j = 0;j < n;j++)
20             {
21                 if(DNA[j][i] == ‘A‘)
22                     list[0]++;
23                 else if(DNA[j][i] == ‘C‘)
24                     list[1]++;
25                 else if(DNA[j][i] == ‘G‘)
26                     list[2]++;
27                 else
28                     list[3]++;
29             }
30             int tmp = 0,ans;
31             for (int k = 0;k < 4;k++)
32                 {
33                     if(list[k] > tmp){
34                         ans = k;
35                         tmp = list[k];
36                     num1 = n - list[k];
37                     }
38                 }
39             num += num1;
40         if(ans == 0) printf("A");
41         if(ans == 1) printf("C");
42         if(ans == 2) printf("G");
43         if(ans == 3) printf("T");
44         }
45         printf("\n%d\n",num);
46     }
47
48     return 0;
49 }
50  

原文地址:https://www.cnblogs.com/Dicer/p/8448143.html

时间: 2024-10-07 03:58:16

DNA Consensus String,( UVa, 1368 )的相关文章

uva 1368 - DNA Consensus String(字符串处理)

uva 1368 - DNA Consensus String Figure 1. DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of four different nucleotides, namely Adenine, Thymine, Guanine, and Cytosine as shown in Figure 1. If we repre

UVA - 1368 DNA Consensus String

DNA Consensus String Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description  Figure 1. DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of four different nuc

UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing

课程好紧啊,只能刷点水题了,几乎都是贪心. UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { int n,kas = 0; while(scanf("%d",&n),n>0){ int r = 0; for(n--;n;n>>=1) r++; printf("Case %d: %d\n",++kas,r); }

UVa1368.DNA Consensus String

原题链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4114 13845357 1368 DNA Consensus String Accepted C++ 0.022 2014-07-07 12:29:30  DNA Consensus String Figure 1. DNA (Deoxyribonucleic Acid) is t

UVA1368 UVALive3602 ZOJ3132 DNA Consensus String

Regionals 2006 >> Asia - Seoul 问题链接:UVA1368 UVALive3602 ZOJ3132 DNA Consensus String. 问题简述:给定m个长度为n的DNA序列,求一个DNA序列,使其到所有这些序列的总hamming距离尽量小,如果有多个解,输出字典顺序的最小解. 解题思路:每个DNA序列的长度相同,对每个DNA序列的每一位DNA码进行统计,选取出现次数最多的码,那么这一位的hamming距离最小.依次类推,每一位都选取出现次数最多的码,那么这

uva 1368 DNA Consensus String 字符串

这学期离散数学的最后一章刚学了类似的东西 什么decoding function和humming distance手算起来才有点难 编程的话就很水了 #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <cmath> #include <set> #include

1368.DNA Consensus String

题目要求是对几个字符串进行分析,得到一个最优的字符串,使它满足与要求的字符串不同的字符之和最小.如果有多种解,则输出字典序最小的. 注意:字符串的结束时 \0  一定要加上 1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 6 const int maxn=1005; 7 char DNA[55][maxn]; 8 struct node{ 9

LA 3602 DNA Consensus String (暴力枚举)

题意:给定m个长度为n的DNA序列,求一个最短的DNA序列,使得总Hamming距离最小. Hamming距离等于字符不同的位置个数. 析:看到这个题,我的第一感觉是算时间复杂度,好小,没事,完全可以暴力,只要对每个串的同一个位置, 都选出现最多的,如果有一样的选ASIIC码小的(因为要求字典序小).然后记录最字符和Hamming距离即可. 代码如下: #include <iostream> #include <cstdio> #include <algorithm>

LA 3602 DNA Consensus String

最近审题老是一错再错,Orz 题目中说求一个Hamming值总和最小的字符串,而不是从所给字符中找一个最小的 这样的话,我们逐列处理,所求字符串当前位置的字符应该是该列中出现次数最多其次ASCII值最小的 代码有点挫了,if语句太多了 1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 using namespace std; 6 7 char gene[5