阿里天池的新任务(简单)(KMP统计子串出现的次数)
阿里“天池”竞赛平台近日推出了一个新的挑战任务:对于给定的一串 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统计子串出现的次数)的更多相关文章
- 计蒜客 阿里天池的新任务—简单( KMP水 )
链接:传送门 思路:KMP模板题,直接生成 S 串,然后匹配一下 P 串在 S 串出现的次数,注意处理嵌套的情况即可,嵌套的情况即 S = "aaaaaa" ,P = " ...
- 计蒜之道 初赛第一场B 阿里天池的新任务(简单)
阿里“天池”竞赛平台近日推出了一个新的挑战任务:对于给定的一串 DNA 碱基序列 tt,判断它在另一个根据规则生成的 DNA 碱基序列 ss 中出现了多少次. 首先,定义一个序列 ww: \displ ...
- poj 3461 Oulipo(kmp统计子串出现次数)
题意:统计子串出现在主串中的次数 思路:典型kmp #include<iostream> #include<stdio.h> #include<string.h> ...
- 2017 计蒜之道 初赛 第一场 B阿里天池的新任务(简单)
题链:"https://nanti.jisuanke.com/t/15500" 本来希望通过找循环节然后套KMP来通过后面题的,可是只过了B题,可能循环节不一定是存在的. #inc ...
- Loj 103、10043 (KMP统计子串个数)
KMP算法学习链接:https://blog.csdn.net/starstar1992/article/details/54913261/ KMP算法:可以实现复杂度为O(m+n) 为何简化了时间复 ...
- POJ 3461 Oulipo 【KMP统计子串数】
传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- hdu 2087剪花布条 (KMP入门 子串出现的次数和子串个数)
剪花布条 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 1686 Oulipo【kmp求子串出现的次数】
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- 统计子串数量,Python基础
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:陈YL PS:如有需要Python学习资料的小伙伴可以加点击下方链接自 ...
随机推荐
- socket.io的websocket示例
写了一个简单的demo,直接上代码吧.用的时候注意一下版本号,可能 socket.io 的 API 有修改~ 效果图 index.html <!DOCTYPE <!DOCTYPE html ...
- Css3 实现循环留言滚动效果(一)
一.常见留言滚动效果示例 html代码 <div class="runList"> <div class="runitem"> < ...
- Android、iOS、和Web如何做灰度发布?
主要参考了: https://www.zhihu.com/question/21714205 https://www.zhihu.com/question/28296375 一.概述 ...
- SpringMVC的拦截器(Interceptor)和过滤器(Filter)的区别与联系
摘自: http://blog.csdn.net/xiaoyaotan_111/article/details/53817918 一 简介 (1)过滤器: 依赖于servlet容器.在实现上基于函数回 ...
- 微信小程序判断用户是否需要再次授权获取个人信息
一.index.js设置如下 //获取用户的授权信息,放到本地缓存中 wx.getSetting({ success: (res) => { if(res.authSetting['scope. ...
- 关于c++ template的branching和Recursion的一段很好的描述
来自: <Learning Boost C++ Libraries> 第290页
- android ScrollView 控制行数
利用ScrollView 来控制textView 显示的行数 <ScrollView android:layout_width="fill_parent" android:l ...
- grid和flex区别
网格容器 VS Flex容器 网格属性 VS Flex属性
- Latex中cls和sty文件有何区别?
Latex中cls和sty文件有何区别? 资源 本文对 LaTeX 中 .cls 和 .sty 文件进行介绍,主要参考了 What are .cls and .sty files?How are th ...
- Gluon Datasets and DataLoader
mxnet.recordio MXRecordIO Reads/writes RecordIO data format, supporting sequential read and write. r ...