阿里“天池”竞赛平台近日推出了一个新的挑战任务:对于给定的一串 DNA 碱基序列 tt,判断它在另一个根据规则生成的 DNA 碱基序列 ss 中出现了多少次。

输出格式

输出一个整数,为 tt 在 ss 中出现的次数。

样例说明

对于第一组样例,生成的 ss 为TTTCGGAAAGGCC

样例输入1

13 2 5 4 9
AGG

样例输出1

1

样例输入2

103 51 0 40 60
ACTG

样例输出2

5
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; char s[];
int w1,w2;
char t[];
int nextt[]; void getnext(int lent)
{
int i=,j=-;
nextt[i]=-;
while(i<lent) {
if(j==-||t[i]==t[j]) {
nextt[++i]=++j;
}
else j=nextt[j];
}
} int kmp(int pos,int lent,int lens)
{
int i=pos,j=,ans=;
while(i<lens) {
if(s[i]==t[j]||j==-) ++i,++j;
else j=nextt[j];
if(j==lent) {
ans++;
j=nextt[j-];
i--;
}
}
return ans;
} int main()
{
int n,a,b,l,r;
scanf("%d %d %d %d %d",&n,&a,&b,&l,&r);
//scanf("%s",t);
cin>>t;
w1=b;
int cous=;
if(b>=l&&b<=r&&b%==){
s[cous++]='A';
}else if(b>=l&&b<=r&&b%==){
s[cous++]='T';
}else if(b<l&&b%==||b>r&&b%==){
s[cous++]='G';
}else if(b<l&&b%==||b>r&&b%==){
s[cous++]='C';
}
for(int i=;i<n;i++){
w2=w1+a;
w2%=n;
if(w2>=l&&w2<=r&&w2%==){
s[cous++]='A';
}else if(w2>=l&&w2<=r&&w2%==){
s[cous++]='T';
}else if(w2<l&&w2%==||w2>r&&w2%==){
s[cous++]='G';
}else if(w2<l&&w2%==||w2>r&&w2%==){
s[cous++]='C';
}
w1=w2;
}
int ans=;
int lens=strlen(s);
int lent=strlen(t);
getnext(lent);
ans=kmp(,lent,lens);
printf("%d\n",ans);
return ;
}

阿里天池的新任务(简单)(KMP统计子串出现的次数)的更多相关文章

  1. 计蒜客 阿里天池的新任务—简单( KMP水 )

    链接:传送门 思路:KMP模板题,直接生成 S 串,然后匹配一下 P 串在 S 串出现的次数,注意处理嵌套的情况即可,嵌套的情况即 S = "aaaaaa" ,P = " ...

  2. 计蒜之道 初赛第一场B 阿里天池的新任务(简单)

    阿里“天池”竞赛平台近日推出了一个新的挑战任务:对于给定的一串 DNA 碱基序列 tt,判断它在另一个根据规则生成的 DNA 碱基序列 ss 中出现了多少次. 首先,定义一个序列 ww: \displ ...

  3. poj 3461 Oulipo(kmp统计子串出现次数)

    题意:统计子串出现在主串中的次数 思路:典型kmp #include<iostream> #include<stdio.h> #include<string.h> ...

  4. 2017 计蒜之道 初赛 第一场 B阿里天池的新任务(简单)

    题链:"https://nanti.jisuanke.com/t/15500" 本来希望通过找循环节然后套KMP来通过后面题的,可是只过了B题,可能循环节不一定是存在的. #inc ...

  5. Loj 103、10043 (KMP统计子串个数)

    KMP算法学习链接:https://blog.csdn.net/starstar1992/article/details/54913261/ KMP算法:可以实现复杂度为O(m+n) 为何简化了时间复 ...

  6. POJ 3461 Oulipo 【KMP统计子串数】

    传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

  7. hdu 2087剪花布条 (KMP入门 子串出现的次数和子串个数)

    剪花布条 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. HDU 1686 Oulipo【kmp求子串出现的次数】

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  9. 统计子串数量,Python基础

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:陈YL PS:如有需要Python学习资料的小伙伴可以加点击下方链接自 ...

随机推荐

  1. flink 有状态udf 引起血案一

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/rlnLo2pNEfx9c/article/details/83422587 场景 近期在做一个画像的 ...

  2. MySQL中的isnull、ifnull和nullif函数用法

    isnull(expr) 如expr为null,那么isnull()的返回值为1,否则返回值为0. mysql>select isnull(1+1); ->0 mysql>selec ...

  3. 面向服务的体系架构(SOA)

    面向服务的体系架构(SOA) 1.面向服务的体系架构(SOA) 面向服务的架构(service-oriented architecture)是Gartner于2O世纪9O年代中期提出的面向服务架构的概 ...

  4. TFS online build change web.config

    概要 TFS online 自动编译时如何修改web.config ref:https://dustinoprea.com/2016/05/06/using-tokenization-token-re ...

  5. appium 报错

    2018-11-27 18:05:56:313 - [Logcat] Logcat terminated with code 0, signal null 2018-11-27 18:05:56:31 ...

  6. eclipse工具中使用Data Source Explorer连接数据库(MySQL)

    1.进入Eclipse工具,打开Data Source Explorer.Window==>Show View==>Data Source Explorer(注:如果找不到请选择Other ...

  7. python(62):保留两位小数

    转载:https://blog.csdn.net/jiandanjinxin/article/details/77752297 在C/C++语言对于整形数执行除法会进行地板除(舍去小数部分). 例如 ...

  8. httpie的使用

    安装 brew install httpie 使用 模拟提交表单 http -f POST yhz.me username=nate 显示详细的请求 http -v yhz.me 只显示Header ...

  9. C++ 函数模板默认的模板参数

    函数的默认模板参数 你可以为模板参数定义默认值,它们被称作 default template arguments(默认模板参数). 它们甚至可以指向前一个模板参数. 1. 可以直接使用 operato ...

  10. 优化实现Mobile/Bumped Diffuse

    在上一篇帖子的基础上增加一张法线贴图即可: Shader "James/Scene/Bumped_Diffuse" { Properties { _MainTex ("B ...