LA 3602 - DNA Consensus String 枚举
题目大意:
给定m个长度均为n的DNA序列,使其(那个啥序列来着,噢)Hamming,(好吧,这单词我复制的T T)序列尽量短,Hamming指的是字符不同位置的个数。(For example, assume we are given the two strings ``AGCAT" and ``GGAAT." The Hamming distance of these two strings is 2 because the 1st and the 3rd characters of the two strings
are different. `AGCAT和GGAAT 的Hamming为2,因为第一和第三字母不一样)如果有多解,取字典序小的。
数据量小,可以直接枚举。.然后就没有然后了。@。@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=1000+10;
char a[50+10][MAXN],ans[MAXN];
int A,C,G,T,diff;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
diff=0;
int n,m;
scanf("%d%d",&m,&n);
for(int i=0;i<m;i++)
scanf("%s",a[i]);
for(int i=0;i<n;i++)
{
A=G=C=T=0;
for(int j=0;j<m;j++)
{
switch(a[j][i])
{
case 'A':A++;break;
case 'C':C++;break;
case 'G':G++;break;
case 'T':T++;break;
}
}
int MAX=0;
MAX=max( max (max (max(MAX,A) ,C) ,G) ,T); if(MAX==A) { diff=diff+C+G+T; ans[i]='A'; }
else if(MAX==C) { diff=diff+A+G+T; ans[i]='C'; }
else if(MAX==G) { diff=diff+C+A+T; ans[i]='G'; }
else if(MAX==T) { diff=diff+C+G+A; ans[i]='T'; }
}
ans[n]='\0'; //注意末尾填结束符,除非你逐个字符输出
printf("%s\n%d\n",ans,diff);
}
}
LA 3602 - DNA Consensus String 枚举的更多相关文章
- 贪心水题。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() { ; ){ ; ) r ...
- LA 3602 DNA Consensus String (暴力枚举)
题意:给定m个长度为n的DNA序列,求一个最短的DNA序列,使得总Hamming距离最小. Hamming距离等于字符不同的位置个数. 析:看到这个题,我的第一感觉是算时间复杂度,好小,没事,完全可以 ...
- LA 3602 DNA Consensus String
最近审题老是一错再错,Orz 题目中说求一个Hamming值总和最小的字符串,而不是从所给字符中找一个最小的 这样的话,我们逐列处理,所求字符串当前位置的字符应该是该列中出现次数最多其次ASCII值最 ...
- uvalive 3602 DNA Consensus String
https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...
- UVa 3602 - DNA Consensus String 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- uva1368 DNA Consensus String
<tex2html_verbatim_mark> Figure 1. DNA (Deoxyribonucleic Acid) is the molecule which contains ...
- DNA Consensus String
题目(中英对照): DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It co ...
- 紫书第三章训练1 E - DNA Consensus String
DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of ...
- uva 1368 DNA Consensus String
这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串. 我的思路就是求每一列每 ...
随机推荐
- hq-源码编译
这里编译整个项目的基本格式是 ./mk + 平台名 +项目名_客户名 +mmm +new 例如 ./mk hq6735_65c_b1k_l1 al811_doov mmm new 编译单个模块 ./m ...
- 分享一下10个常用jquery片段
1. 图片预加载 (function($) { var cache = []; // Arguments are image paths relative to the current page. ...
- mysql 数据库 存储数据类型
int 类型的数据 可以在数据库里存成 char字符串类型的数据: 纯数字的字符串 可以在数据库里存储为 int的数据类型.
- 【2017 Multi-University Training Contest - Team 2】 Regular polygon
[Link]: [Description] 给你n个点整数点; 问你这n个点,能够组成多少个正多边形 [Solution] 整点只能构成正四边形. 则先把所有的边预处理出来; 枚举每某两条边为对角线的 ...
- UVA 11346 Probability (几何概型, 积分)
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=2321">https://uva ...
- eclipse- MAT安装及使用
1.安装eclipse mat插件 1)查看当前eclipse版本 进入eclipse目录:右击eclipse图标,看到安装目录/home/zhangshuli/adt-bundle-linux-x8 ...
- java中goto语句
goto是java中一个保留字,但在语言中并未使用它. goto语句起源于汇编语言的程序控制,是源码级上的跳跃,这使其招致了不好的声誉,若一个程序总是从一个地方跳转到另一个地方, 还有什么办法能识别程 ...
- C# 截取中英文混合字符串分行显示宽度相同
/// <summary> /// 截取方法名显示宽度 /// </summary> /// <param name=" ...
- dataguard主备延迟多长时间的查询方法
select value from v$dataguard_stats where name='apply lag';
- Linux启动(续)
runlevel (启动级别): 查看命令 :who -r 或 runlevel 0:halt 关机 1:单用户模式,直接以管理员身份登录,不需要密码 ...