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 ...
随机推荐
- java学习之spring基础
0x00前言 spring框架应用的是ioc模式,ioc模式是指控制反转模式,本质是你不去创建对象让spring框架给你创建对象你去使用对象.多种开发模式通过配置文件和注解的方式去开发的都很值得去学习 ...
- C#实践炸飞机socket通信
一.前言 最近老师要求做课设,实现一个 "炸飞机" 游戏,我是负责UI界面实现和Socket通信实现的,在这里想总结一下我实现Socket的具体过程,对其中的产生的问题和实现的方法 ...
- Day09:switch——case结构的使用详解
switch--case结构的使用详解 什么是switch--case结构 他也是一种多选择结构 switch--case结构是类于if--else的语法,通过比较而输出对应的内容: 通俗的讲,好比我 ...
- 嵌入式-C语言基础:malloc动态开辟内存空间
#include<stdio.h> #include<stdlib.h> int main() { // char *p;//定义一个野指针:没有让它指向一个变量的地址 // ...
- 真正“搞”懂HTTP协议04之搞起来
前两篇文章,我们从空间和时间的角度都对HTTP有了一定的学习和理解,那么基于上一篇的HTTP发展的时间顺序,我会在后面的文章由浅入深,按照HTTP版本内容的更迭,一边介绍相关字段的使用方法,一边讲解其 ...
- cookies和session总结
1.作为基础知识,但是也是容易被我们忽略的知识. 2.从我的一次面试中,面试官问到,session是什么?和cookies有什么关系,当时我以为很简单,便顺口回答到,session是为了解决http无 ...
- C++快速幂
C++快速幂 快速幂的作用: 当我们做一些高次幂的计算时,就不能直接进行暴力的计算.例如:需要计算2^n 并且n≤10^18.这时候如果我们直接进行暴力的计算,时间复杂度为O ( n ),那么肯定会超 ...
- WebApi如何启用Session并且使用
首先打开项目的Global.asax文件,重新方法init public override void Init() { //注册事件 this.AuthenticateRequest += WebAp ...
- 关于linux mint新增加的鼠标样式的示例图片不能正确显示的解决办法
前言 我相信你在linux mint 做鼠标主题美化的时候一定遇到过这样的问题 没错!!! 下载的鼠标的主题的示例图片不能正确显示,当然这样虽然不影响正常的鼠标主题更换使用,但是对于我这种强迫症来说简 ...
- day 26 form表单标签 & CSS样式表-选择器 & 样式:背景、字体、定位等
html常用标签 嵌套页面 <!-- 嵌套页面 --> <div> <!-- target属性值可以通过指定的iframe的name属性值, 实现超链接页面,在嵌套页面展 ...