UVA-1368 DNA Consensus String(思路)】的更多相关文章

这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串. 我的思路就是求每一列每个基因A.C.G.T的数量,找到最大值,最大值可能不止一个,但是锁定字典序最小的那个为所求字符串当前列的值,求解实例如下所示 TATGATACTAAGCTACAAAGATCCTGAGATACTAAGATGT 对于上述字符串,第一列A,C,G,T的值分别为1,0,0,4,可见最大值为4,说明当前列到每…
https://cn.vjudge.net/problem/UVA-1368 二维的hamming距离算法: For binary strings a and b the Hamming distance is equal to the number of ones (population count) in a XOR b. int hamming_distance(unsigned x, unsigned y) { ; unsigned val = x ^ y; // Count the n…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1603 题意 问使m个n长碱基序列汉明码最小的序列 思路 明显,取最频繁的 代码 #include <algorithm> #include <cassert> #include <cmath> #include <cstdio&…
UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { ; ){ ; ) r++; printf("Case %d: %d\n",++kas,r); } ; } LA 3602 DNA Consensus String 贪心构造,每一位上选出现次数最多的. #include<bits/stdc++.h> using namespace std; ,ma…
<tex2html_verbatim_mark> 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 represent a…
题目(中英对照): 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 represent a nucleotide by its initial…
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 represent a nucleotide by its initial character…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举每一位字母是什么. 从小到大枚举. 然后计算每一位的总贡献是多少. 取最小的那个输出. [代码] #include <bits/stdc++.h> using namespace std; const int M = 50; const int N = 1e3; const char b[] = {'A','C','G','T'}; int T,n,m; char s[M+10][N+100]; int main(){ #…
题目链接:https://vjudge.net/problem/UVA-1368 题意:给出一组字符串,求出一组串,使与其他不同的点的和最小 题解:这个题就是一个点一个点求,利用桶排序,求出最多点数目的集合,如果点数相同,则按字母序最小的点为准 ac代码 #include<iostream>#include<cstdio>#include<cstring>using namespace std;char ch[60][1100],ans[1100];int main()…
题目: 链接 题意: 题目虽然比较长,但读完之后题目的思路还是比较容易想出来的. 给出m个长度为n的字符串(只包含‘A’.‘T’.‘G’.‘C’),我们的任务是得出一个字符串,要求这个字符串与给出的m个字符串的汉明距离的和最小,输出这个字符串和最小的汉明距离和. 如果有多个符合题意的字符串,就输出字典序最小的那个字符串. 思路: 1.首先给出汉明距离的定义: 汉明距离表示相同长度的字对应位不同的数量. 例如: 10100和11000的汉明距离就是2. 2.对m个字符串的每一位分别统计‘A’.‘T…
https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序最小的解. ps:汉明距离指的是两个等长字符串中字符不同的位置的个数. 思路: 贪心原则,记录每一个位置上哪个字母出现的次数最多,如果有相同的就取字典序最小的那个,然后放进答案就可以了. 代码: #include <iostream> #include <string> #includ…
题目描述:算法竞赛入门经典习题3-7 题目思路:每列出现最多的距离即最短 #include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { int m,n ; scanf("%d%d",&m,&n) ; ][n+] ; ;i<m;i++) scanf("%s",&c[i]) ; //for(int i=0;i<m;i++) /…
#include <stdio.h>#include <string.h> int main(){    int a[4][1000]; // A/C/G/T在每列中出现的次数    char c, x;    char bas[4] = { 'A', 'C', 'G', 'T' };    int T, m, n, i, j, k, dist;    scanf("%d", &T);    while (T--)    {        scanf(&…
题意:给定m个长度为n的DNA序列,求一个最短的DNA序列,使得总Hamming距离最小. Hamming距离等于字符不同的位置个数. 析:看到这个题,我的第一感觉是算时间复杂度,好小,没事,完全可以暴力,只要对每个串的同一个位置, 都选出现最多的,如果有一样的选ASIIC码小的(因为要求字典序小).然后记录最字符和Hamming距离即可. 代码如下: #include <iostream> #include <cstdio> #include <algorithm>…
原题地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1603 题目大意: 给定m个长度均为n的DNA序列,使其(那个啥序列来着,噢)Hamming,(好吧,这单词我复制的T T)序列尽量短,Hamming指的是字符不同位置的个数.(For example, assume we are given the two stri…
最近审题老是一错再错,Orz 题目中说求一个Hamming值总和最小的字符串,而不是从所给字符中找一个最小的 这样的话,我们逐列处理,所求字符串当前位置的字符应该是该列中出现次数最多其次ASCII值最小的 代码有点挫了,if语句太多了 //#define LOCAL #include <iostream> #include <cstdio> #include <cstring> using namespace std; ][], ans[]; ]; int main(v…
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. Write a function to find all the 10-letter-long seq…
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. Write a function to find all the 10-letter-long seq…
简单的贪心 ~ #include <cstdio> #include <cstdlib> #include <cmath> #include <map> #include <set> #include <stack> #include <vector> #include <sstream> #include <string> #include <cstring> #include <…
题意:有一个n*n的01矩阵,任务是把尽可能少的0变成1,使得每个元素的上.下.左.右元素之和为偶数. 思路:很容易想到的思路是枚举每个点是0还是1,因为n<=15,复杂度就是2^225显然TLE.注意到每次确定一样以后,下一行就是可以被确定的!所以,只要枚举第一行的状态,就可以推出每一行的状态,复杂度是15*2^15,. #include<cstdio> #include<iostream> #define INF 0x3f3f3f3f #define MAXN 20 us…
题意 : 给出几组由数组定义与赋值构成的编程语句, 有可能有两种BUG, 第一种为数组下标越界, 第二种为使用尚未定义的数组元素, 叫你找出最早出现BUG的一行并输出, 每组以' . '号分隔, 当有两组输入都是' . '时结束程序 分析 : 由于错误的类型由题意所述的两种组成, 所以我们需要知道每个数组的长度与每个已经被赋值定义过的数组元素大小, 因此可以定义map<string, int> Info 来存储数组名和这个数组的大小两个信息, 在定义一个map<string, map&l…
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5659 题意: 你有一个只包含"(" 和 ")" 的串,每一个位置有个数值,这个数值是当前的左括号-右括号的值. 例:()() 数值就是1010. 给你一个打乱了的数值,要你构造出字典序最小的字符串. 题解: 因为左括号比右括号…
区间dp,两个str一起考虑很难转移. 看了别人题解以后才知道是做两次dp. dp1.str1最坏情况下和str2完全不相同,相当于从空白串开始刷. 对于一个区间,有两种刷法,一起刷,或者分开来刷. 规定[i][i-1]为空串,这样一起刷可以归结为第二种情况. 合并的时候,大的区间的次数<=小的区间的,和新加入区间的字符有关. 小的区间是一个字符一个字符的变成大区间的. 所以每次考虑新加入区间的尾部字符j,枚举k划分区间[i][k-1],[k][j]. 要使得刷的次数减少,只有尽量一起刷.比如a…
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 都是<算法竞赛入门经典(第二版)>的题目,标题上没写(第二版) 题目:算法竞赛入门经典 3-7/UVa1368:DNA Consensus String 代码: //UVa1368 - DNA Consensus String #include<iostream> using namespace std; #define MAX_M 52 #define MAX_N 1005 char DNA[MAX…
题目连接:147 - Dollars 题目大意:有11种硬币, 现在输入一个金额, 输出有多少种组成方案. 解题思路:uva 674 的升级版,思路完全一样, 只要处理一下数值就可以了. #include <stdio.h> #include <string.h> const int N = 30005; const int val[11] = {5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000}; long long n,…
Problem A matrix is a rectangular table of values divided into rows and columns. An m×nm×n matrix has mm rows and nn columns. Given a matrix AA, we write Ai,jAi,j to indicate the value found at the intersection of row ii and column jj. Say that we ha…
    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 77786   Accepted: 31201 Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are out of order with respect to each other. For ins…
题目链接 题意: 给n串有疾病的DNA序列,现有一串DNA序列,问最少修改几个DNA,能使新的DNA序列不含有疾病的DNA序列. 思路: 构建AC自动机,设定end结点,dp[i][j]表示长度i的前缀串走到自动机的j点最少需要修改几个DNA.状态转移方程.那么只要转移到下一个的DNA不是end结点就能转移,如果下一个DNA不和原序列不一样就+1. #include <bits/stdc++.h> const int N = 50 + 5; const int M = 1000 + 5; co…
Given an input string, reverse the string word by word. For example,Given s = "the sky is blue",return "blue is sky the". For C programmers: Try to solve it in-place in O(1) space. Clarification: What constitutes a word?A sequence of n…
Given a string, you need to reverse the order of characters in each word within a sentence whilestill preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contest"Output: "s'teL ekat edoCteeL tsetnoc"Note:…