思路一:

这题需要桶+哈希(简化版像A 1  B  2 ......)

具体:

先把数据输入

再枚举可能的右端点,再由右端点得到左端点(l和r相差k)

在 l到r 区间内将这一段区间哈希成一个4进制数后(A 0  C  1  G 2   T   3)(装成函数),将其放入桶中。

最后在枚举所有可能的区间,取他们出现次数的max 值并输出这个值

转换函数:

先开一个ans记录答案,再把l到r区间内的字符遍历一遍,如果是’a‘ t=0其他的类同(t用来记录这个位置上的Hash值),最后ans=ans*4+t(先给t腾个位置再把它放进去,又因为是4进制所以乘4,其效果与10进制下乘10相同),最后,返回ans

思路二:

题目即统计每种连续 k 个碱基的出现次数。
发现 k 很小,并且每一位状态只有 4 种,所以本质不同的串最多有 4 k 个,于
是我们可以用 4 进制数表示。注意到 4 10 = 220,因此可以直接将这些状态出现的
次数存起来。
这里计算一个串的 Hash 值有两种方法,第一种是每个串都重新计算一遍,时
间复杂度为 O(nk),第二种是利用位运算将无用状态取出,并加入新状态,时间
复杂度为 O(n)。这两个复杂度的代码均可。
思路一程序:
 1 #include<bits/stdc++.h>
2 using namespace std;
3 const int N=(1<<20)+1;
4 string s;
5 int buk[N]={0};
6 int k;
7 int translate(int l,int r)//A 0 C 1 G 2 T 3 四进制
8 {
9 //s[l]~s[r]
10 int ans=0;
11 for(int i=l;i<=r;i++)
12 {
13 int t=0;
14 if(s[i]=='A') t=0;
15 else if(s[i]=='C') t=1;
16 else if(s[i]=='G') t=2;
17 else if(s[i]=='T') t=3;
18 ans=ans*4+t;
19 }
20 return ans;
21 }
22 int main()
23 {
24 getline(cin,s);
25 cin>>k;
26 for(int r=k-1;r<s.length();++r)
27 {
28 int l=r-k+1;
29 int t=translate(l,r);
30 buk[t]++;
31 // cout<<t<<" ";
32 }
33
34 int rans=0;
35 for(int l=0;l<=s.length()-k;l++)
36 {
37 int r=l+k-1;
38 // if(buk[translate(l,r)]>rans) rans=buk[translate(l,r)];
39 rans=max(rans,buk[translate(l,r)]);
40 }
41 cout<<rans;
42 // cout<<buk[00000];
43 return 0;
44 }

思路二代码:

 1 #include <cstdio>
2 #include <cstring>
3
4 const int MAXN = 5000000;
5 const int MAXR = 1 << 20;
6
7 char a[MAXN + 5];
8 int n, m, k, cnt[MAXR + 5], f[26], h, ans;
9 int DNA[MAXN + 5];
10
11 int main()
12 {
13 freopen("dna.in", "r", stdin);
14 freopen("dna.out", "w", stdout);
15
16 f['G' - 'A'] = 1; f['C' - 'A'] = 2; f['T' - 'A'] = 3;
17
18 scanf("%s", a);
19 n = strlen(a);
20 scanf("%d", &k);
21
22 for (int i = 0; i < n; i++)
23 DNA[i] = f[a[i] - 'A'];
24
25 for (int i = 0; i <= n - k; i++)
26 {
27 for (int j = 0; j < k; j++)
28 h = h << 2 | DNA[i + j];
29
30 ++cnt[h];
31 h = 0;
32 }
33
34 for (int i = 0; i < (1 << (k << 1)); i++) if (ans < cnt[i])
35 ans = cnt[i];
36
37 printf("%d\n", ans);
38 return 0;
39 }

DNA的更多相关文章

  1. [LeetCode] Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  2. DNA解链统计物理

    来源:Kerson Huang, Lectures on Statistical Physics and Protein Folding, pp 24-25 把双链DNA解开就像拉拉链.设DNA有\( ...

  3. AC自动机+DP HDOJ 2457 DNA repair(DNA修复)

    题目链接 题意: 给n串有疾病的DNA序列,现有一串DNA序列,问最少修改几个DNA,能使新的DNA序列不含有疾病的DNA序列. 思路: 构建AC自动机,设定end结点,dp[i][j]表示长度i的前 ...

  4. [Leetcode] Repeated DNA Sequences

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  5. 利用Python【Orange】结合DNA序列进行人种预测

    http://blog.csdn.net/jj12345jj198999/article/details/8951120 coursera上 web intelligence and big data ...

  6. cfDNA(circulating cell free DNA)全基因组测序

    参考资料: [cfDNA专题]cell-free DNA在非肿瘤疾病中的临床价值(好) ctDNA, cfDNA和CTCs有什么区别吗? cfDNA你懂多少? 新发现 | 基因是否表达,做个cfDNA ...

  7. 3.Complementing a Strand of DNA

    Problem In DNA strings, symbols 'A' and 'T' are complements of each other, as are 'C' and 'G'. The r ...

  8. 2. Transcribing DNA into RNA

    Problem An RNA string is a string formed from the alphabet containing 'A', 'C', 'G', and 'U'. Given ...

  9. 1.Counting DNA Nucleotides

    Problem A string is simply an ordered collection of symbols selected from some alphabet and formed i ...

  10. leetcode 187. Repeated DNA Sequences 求重复的DNA串 ---------- java

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

随机推荐

  1. 图学习【参考资料2】-知识补充与node2vec代码注解

    本项目参考: https://aistudio.baidu.com/aistudio/projectdetail/5012408?contributionType=1 *一.正题篇:DeepWalk. ...

  2. PHP使用PHPmailer类和smtp发送邮件

    开启邮件smtp服务 设置授权码 引入phpmailer类,smtp类本地下载https://github.com/PHPMailer/PHPMailer //下载PHPMailer并开启php_op ...

  3. RSA、DSA 和 ECC 加密算法有什么区别?

    RSA.DSA 和 ECC 加密算法是用于在公钥基础设施中生成密钥的主要算法. 公钥基础设施 (PKI) 用于管理互联网通信和计算机网络中的身份和安全性. 启用 PKI 的核心技术是公钥密码术,这是一 ...

  4. Goland环境中Go module配置

    [现象] 从go vendor切换到go module之后,import包解析有问题.如下所示: 对应的go modules也没解析出来 [原因] 有两点原因: goland中go module配置存 ...

  5. 云原生学习笔记-1-docker

    一.基础环境说明 1.操作系统:Centos7.6:1master:2node 2.docker版本:docker-ce 19.03.8-3 二.docker安装 1.使用阿里镜像仓库,mirror. ...

  6. i春秋wanna to see your hat?

    打开题目网页发现是个选择帽子的网页,点击超链接进入一个网页让我们输入我们的name然后匹配帽子颜色(其实不管怎么填都是绿色的)这里也有个注册窗口 先查看源码没什么特别发现,再试试抓包吧 在这个界面抓包 ...

  7. swap,传参实质

    void swap(int a,int b){ int s=a; a=b; b=s; } int main(){ int x=1,y=2; swap(x,y); } 上面的函数并不能实现交换,因为传参 ...

  8. Python: 对程序做性能分析及计时统计

    1.对整个程序的性能分析 如果只是想简单地对整个程序做计算统计,通常使用UNIX下的time命令就足够了. (base) ➜ Learn-Python time python someprogram. ...

  9. fiddler提示"The system proxy was changed,click to reenable fiddler capture"的解决方法

    之前用fiddler 一直都是正常的,但是过了几个月再次使用的时候没几秒钟就提示:The system proxy was changed,click to reenable fiddler capt ...

  10. 复现MySQL的索引选择失误以及通过OPTIMIZER_TRACE分析过程

    复现MySQL的索引选择失误以及通过OPTIMIZER_TRACE分析过程 验证环境:MySQL 5.7.39 windows-pc 一.构造数据(生成150万数据) 构建一张账户表,带有一级部门id ...