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…
这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串. 我的思路就是求每一列每个基因A.C.G.T的数量,找到最大值,最大值可能不止一个,但是锁定字典序最小的那个为所求字符串当前列的值,求解实例如下所示 TATGATACTAAGCTACAAAGATCCTGAGATACTAAGATGT 对于上述字符串,第一列A,C,G,T的值分别为1,0,0,4,可见最大值为4,说明当前列到每…
题目 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…
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…
<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…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举每一位字母是什么. 从小到大枚举. 然后计算每一位的总贡献是多少. 取最小的那个输出. [代码] #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()…
https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序最小的解. ps:汉明距离指的是两个等长字符串中字符不同的位置的个数. 思路: 贪心原则,记录每一个位置上哪个字母出现的次数最多,如果有相同的就取字典序最小的那个,然后放进答案就可以了. 代码: #include <iostream> #include <string> #includ…
题意:给定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…
#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(&…
题目描述:算法竞赛入门经典习题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++) /…
题目: 链接 题意: 题目虽然比较长,但读完之后题目的思路还是比较容易想出来的. 给出m个长度为n的字符串(只包含‘A’.‘T’.‘G’.‘C’),我们的任务是得出一个字符串,要求这个字符串与给出的m个字符串的汉明距离的和最小,输出这个字符串和最小的汉明距离和. 如果有多个符合题意的字符串,就输出字典序最小的那个字符串. 思路: 1.首先给出汉明距离的定义: 汉明距离表示相同长度的字对应位不同的数量. 例如: 10100和11000的汉明距离就是2. 2.对m个字符串的每一位分别统计‘A’.‘T…
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5659 题意: 你有一个只包含"(" 和 ")" 的串,每一个位置有个数值,这个数值是当前的左括号-右括号的值. 例:()() 数值就是1010. 给你一个打乱了的数值,要你构造出字典序最小的字符串. 题解: 因为左括号比右括号…
D. Wizards and Roads 题目连接: http://www.codeforces.com/contest/167/problem/D Description In some country live wizards. They love to build cities and roads. The country used to have k cities, the j-th city (1 ≤ j ≤ k) was located at a point (xj, yj). It…
这是悦乐书的第259次更新,第272篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第126题(顺位题号是557).给定一个字符串,您需要反转句子中每个单词中的字符顺序,同时仍保留空格和初始单词顺序.例如: 输入:"Let's take LeetCode contest" 输出:"s'teL ekat edoCteeL tsetnoc" 注意:在字符串中,每个单词由单个空格分隔,并且字符串中不会有任何额外的空格. 本次解题使用的开发工具是…
这是悦乐书的第206次更新,第218篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第74题(顺位题号是345).编写一个函数,它将一个字符串作为输入,并仅反转一个字符串的元音.例如: 输入:"hello" 输出:"holle" 输入:"leetcode" 输出:"leotcede" 注意:元音不包括字母"y". 本次解题使用的开发工具是eclipse,jdk使用的版本是1.8,…
UVA.11384 Help is needed for Dexter (思维题) 题意分析 同样水题一道,这回思路对了. 给出数字n,面对一个1,2,3,4--n的数字序列,你可以对他们的部分或者全部减去一个相同数字,最后使得这个序列变为全0的序列,求这样操作的次数最小值. 一开始着手想的是两两分组,既然能两两分组,为什么不三三分组呢?既然能三三分组,为什么不能四四分组呢?不难联想到二分法,即折半分组,看如下的例子: n = 9 1,2,3,4,5,6,7,8,9 折半后 1,2,3,4 5,…
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN], b[MAXN]; int main(void) //UVA 11292 The Dragon of Loo…
[3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring (2019年1月22日,复习) [6]ZigZag Conversion (2019年1月22日,复习) [8]String to Integer (atoi) (2019年1月22日,复习) [10]Regular Expression Matching (2019年1月22日,复习) [12]In…
1.3 Given two strings, write a method to decide if one is a permutation of the other. 这道题给定我们两个字符串,让我们判断一个是否为另一个的全排列字符串.在LeetCode中,关于排列的题有如下几道,Permutation Sequence 序列排序,Permutations 全排列, Permutations II 全排列之二 和 Next Permutation 下一个排列.这道题跟它们比起来,算是很简单的…
这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.php?pid=2629 #include <iostream> #include <string> using namespace std; int main() { int n,t; string home,a; cin>>n; ; k < n ; k++) { ci…
Given a string s and a list of strings dict, you need to add a closed pair of bold tag <b> and </b> to wrap the substrings in s that exist in dict. If two such substrings overlap, you need to wrap them together by only one pair of closed bold…
目录 前言 一.憨憨初解 1.思路 2.代码 3.战绩 4.反思 二.看懂再解 1.思路 2.代码 3.C++版战绩 总结 前言 题目来源:https://leetcode.cn/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof/ 这个题目有官方解释的有限状态自动机,也有用正则肝的,甚至有暴躁老哥打算直接把这题撕了的,但是,还得是评论区里人才多,总有大佬能肝出来清晰的题解,这波记录一下,食用这个题目的过程. 大佬讲解链接:https://www.bili…
课程概要 String 字符串 String字符串常用方法 StringBuffer StringBuilder String字符串: 1.实例化String对象 直接赋值  String str="Hello";  推荐这种 使用关键字new  String str1=new String("Hello"); 在内存中开辟2个空间 如图: 源代码 StringDemo01.java 2.String内容的比较 String str="Hello"…
1.Java字符串String A.实例化String字符串:直接赋值(更合理一些,使用较多).使用关键字new. B.String内容的比较 // TODO Auto-generated method stub // int a=10; // int b=10; // System.out.println(a==b); String str="Hello"; String str1=new String("Hello"); System.out.println(s…
C++ 提供的 string 类包含了若干实用的成员函数,大大方便了字符串的增加.删除.更改.查询等操作. 插入字符串 insert() 函数可以在 string 字符串中指定的位置插入另一个字符串,它的一种原型为: string& insert (size_t pos, const string& str); pos 表示要插入的位置,也就是下标:str 表示要插入的字符串,它可以是 string 变量,也可以是C风格的字符串. 请看下面的代码: #include <iostrea…