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 ...
随机推荐
- 支持JDK19虚拟线程的web框架之四:看源码,了解quarkus如何支持虚拟线程
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 前文链接 支持JDK19虚拟线程的web框架,之一:体 ...
- 前端学习 linux —— 软件安装(Ubuntu)
软件安装(Ubuntu) 本篇主要讲解 ubuntu 中软件的安装.apt 的源.内网部署案例(graylog 为例),最后是 python 开发准备. apt 和 rpm 在linux 第一篇我们知 ...
- 痞子衡嵌入式:MCUXpresso IDE下高度灵活的FreeMarker链接文件模板机制
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是MCUXpresso IDE下高度灵活的FreeMarker链接文件模板机制. 痞子衡之前写过一篇文章 <MCUXpresso I ...
- typora实现多平台发布文章
源码下载 前言 之前写过一片文章,typora 使用CSDN作为图床,用来存储 markdown 文章的图片资源文件.后来发现 typora 还可以自定义导出命令,那么也可以利用这个功能实现直接发布到 ...
- xml中出现< >&等特殊字符如何存储
特殊字符用下面对应得符号代替. < <= > >= & ' " < <= > >= & ' "
- MySQL锁,锁的到底是什么?
MySQL锁系列文章已经鸽了挺久了,最近赶紧挤了挤时间,和大家聊一聊MySQL的锁. 只要学计算机,「锁」永远是一个绕不过的话题.MySQL锁也是一样. 一句话解释MySQL锁: MySQL锁是解决资 ...
- Django基础笔记6(Django中间件)
Django自带的中间件 中间件执行流程 自定义中间件 Middle.py class Middle1(MiddlewareMixin): def process_request(self, requ ...
- ORM增删改查 django请求生命周期图 django路由层及反向解析
目录 可视化界面之数据增删改查 1.建表 2.数据展示功能 3.数据添加功能 4.数据编辑功能 5.数据删除功能 django请求生命周期流程图 django路由层 1.路由匹配 2.转换器功能 pa ...
- java顺序数组插入元素
本文主要阐明已知顺序数组,在数组中插入一个数据元素,使其仍然保持有序. 关键是寻找num在原数组中插入的位置: 当num在原数组中是最大的情况,num应该插入到原数组的末尾. 否则,应该遍历原数组,通 ...
- jmeter 之性能分布式压测
背景: 当并发量达到一定数量时,单台测试设备不足以支撑,甚至会出现内存溢出等情况,解决这个问题就可用分布式测试,使用多台测试设备来达到更大的用户并发数. 原理: 1.一台设备作为调度机(master) ...