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 ...
随机推荐
- mindxdl--common--http_handler.go
// Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved.// Package common this file ...
- 基于python的数学建模---时间序列
JetRail高铁乘客量预测--7种时间序列方法 数据获取:获得2012-2014两年每小时乘客数量 import pandas as pd import numpy as np import mat ...
- vscode分级文件夹
如果vscode不小心设置成文件独立展开,一堆文件看着很乱 这样设置 首选项-设置-功能-资源管理器-compack folders 就可以折叠文件夹了
- 第1章-Spring的模块与应用场景
目录 一.Spring模块 1. 核心模块 2. AOP模块 3. 消息模块 4. 数据访问模块 5. Web模块 6. 测试模块 二.集成功能 1. 目标原则 2. 支持组件 三.应用场景 1. 典 ...
- 记一次hook mac地址实现伪装硬件码
1. 前言 好久没写文章了,工作比较忙,不过我还是对技术比较热爱,即使它不能给我带来利益,保持初心. 工作期间遇到一个问题,连接vpn的软件是校验机器硬件码,不是公司电脑不让使用vpn软件,上下班已经 ...
- Python异步协程(asyncio详解)
续上篇讲解yield from博客,上篇链接:https://www.cnblogs.com/Red-Sun/p/16889182.html PS:本博客是个人笔记分享,不需要扫码加群或必须关注什么的 ...
- Java开发学习(四十五)----MyBatisPlus查询语句之映射匹配兼容性
1.映射匹配兼容性 我们已经能从表中查询出数据,并将数据封装到模型类中,这整个过程涉及到一张表和一个模型类: 之所以数据能够成功的从表中获取并封装到模型对象中,原因是表的字段列名和模型类的属性名一样. ...
- Linux系统下安装tomcat步骤
安装参考教程:https://www.cnblogs.com/li150dan/p/12535067.html 说明:jdk自动安装后路径是/usr/lib/jvm 在"vim /etc/p ...
- 【数据库】pgsql窗口函数,分组求sum的方式
select distinct quantity, standard_cost, sum(a.quantity*a.standard_cost) over(partition by ...
- Day33:String类及其常用方法详解
String类 1.1 String类概述 Java中字符串属于对象,String类用于创建和操作字符串. 最简单的字符串创建:直接通过String创建 String str="工地佬&qu ...