DNA


思路一:
这题需要桶+哈希(简化版像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
思路二:
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的更多相关文章
- [LeetCode] Repeated DNA Sequences 求重复的DNA序列
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- DNA解链统计物理
来源:Kerson Huang, Lectures on Statistical Physics and Protein Folding, pp 24-25 把双链DNA解开就像拉拉链.设DNA有\( ...
- AC自动机+DP HDOJ 2457 DNA repair(DNA修复)
题目链接 题意: 给n串有疾病的DNA序列,现有一串DNA序列,问最少修改几个DNA,能使新的DNA序列不含有疾病的DNA序列. 思路: 构建AC自动机,设定end结点,dp[i][j]表示长度i的前 ...
- [Leetcode] Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- 利用Python【Orange】结合DNA序列进行人种预测
http://blog.csdn.net/jj12345jj198999/article/details/8951120 coursera上 web intelligence and big data ...
- cfDNA(circulating cell free DNA)全基因组测序
参考资料: [cfDNA专题]cell-free DNA在非肿瘤疾病中的临床价值(好) ctDNA, cfDNA和CTCs有什么区别吗? cfDNA你懂多少? 新发现 | 基因是否表达,做个cfDNA ...
- 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 ...
- 2. Transcribing DNA into RNA
Problem An RNA string is a string formed from the alphabet containing 'A', 'C', 'G', and 'U'. Given ...
- 1.Counting DNA Nucleotides
Problem A string is simply an ordered collection of symbols selected from some alphabet and formed i ...
- 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 ...
随机推荐
- IO学习笔记
IO File 概述 构造方法 代码实现: public class FileDemo001 { public static void main(String[] args) { File f1 = ...
- 13.django-admin组件
Django内置了一个强大的组件叫Admin,提供给网站管理员快速开发运营后台的管理站点,下面通过案例进行操作 1.创建模型类 模型类如下: from django.db import models ...
- LINQ to Entities 不识别方法“System.String get_Item(System.String)”,因此该方法无法转换为存储表达式。
在使用EF的FirstOrDefault时出现异常.原因是EF的查询条件需要是一个变量否者就会出现这个原因 错误的代码 var userid= db.UserList.Where(u => u. ...
- 重学c#系列——委托和匿名函数[二十五]
前言 简单介绍一下什么是委托. 正文 以前也写过委托,这次算是重新归档,和新的补充吧. https://www.cnblogs.com/aoximin/p/13940125.html 有些人说委托是函 ...
- MySQL数据库:6、约束的概述及语法
Python基础之MySQL数据库 目录 Python基础之MySQL数据库 一.约束概述 1.为什么要约束 2.什么是约束 3.约束的分类 4.查看当前表已有的约束 二.约束语法及用法 1.无符号 ...
- C# DataTable 虚拟Sql临时表,可以做一些处理
/// <summary> /// 获取临时表-和数据库表一样的的表结构的才可以 /// </summary> /// <param name="SourceT ...
- ArcObjects SDK开发 003 宏观角度看ArcObjects SDK
1.为什么要宏观上看ArcObjects SDK ArcObjects SDK库是一个非常庞大复杂COM组件集合,ArcGIS10.0有1000多个枚举.90多个结构体.5000多个接口以及4000多 ...
- 如何搭建自己的CICD流水线,实现自动编译部署功能?
之前使用过GitLab的CICD流水线,有多种环境,点击即可编译部署,十分的方便. 如何在个人项目中搭建自己的CICD流水线,实现push代码后自动编译并部署呢?这里使用到阿里云 云效DevOps,阿 ...
- vba 数组判断与转换
Private Function CountArr(arr)'*****************************'计算数组是几维数组'***************************** ...
- 开发一个最简单的iOS App
开发一个最简单的iOS App 大家好,我是孜孜不倦学习的Zhangbeihai. 上月底我组织了[组队学习]TensorFlow 入门课程(中文) ,截至目前有300多同学加入.主要就是 Tenso ...