计蒜客 阿里天池的新任务—简单( KMP水 )
**链接:****传送门 **
思路:KMP模板题,直接生成 S 串,然后匹配一下 P 串在 S 串出现的次数,注意处理嵌套的情况即可,嵌套的情况即 S = "aaaaaa" ,P = "aa" P 串在S 串中出现了 5 次。
/*************************************************************************
> File Name: jsk02e2.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月21日 星期日 10时28分09秒
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1000100;
char S[MAX_N] , P[MAX_N];
int W[MAX_N];
void init(int n,int a,int b,int L,int R){
W[0] = b;
for(int i = 1 ; i < n ; i++) W[i] = ( W[i-1] + a ) % n;
for(int i = 0 ; i < n ; i++){
if( W[i] >= L && W[i] <= R){
if( W[i] & 1 ) S[i] = 'T';
else S[i] = 'A';
}
else{
if( W[i] & 1 ) S[i] = 'C';
else S[i] = 'G';
}
}
}
// KMP部分
void Build_Next(const char* pat,int next[]){
int i = 1 , t = 0 , plen = strlen(pat);
next[1] = 0;
while( i < plen + 1 ){
while( t > 0 && pat[i-1]!=pat[t-1] ) t = next[t];
++t , ++i;
if( pat[i-1] == pat[t-1] ) next[i] = next[t];
else next[i] = t;
}
while( t > 0 && pat[i-1] != pat[t-1] ) t = next[t];
++i , ++t;
next[i] = t;
}
int KMP(const char* text , const char* pat){
int i , j , n;
int tlen = strlen(text) , plen = strlen(pat);
int next[plen+2];
Build_Next(pat,next);
i = 0 , j = 1 , n = 0;
while( plen + 1 - j <= tlen - i ){
if( text[i] == pat[j-1] ){
++i , ++j;
if( j == plen + 1 ){
// matches[n++] = i - plen; // 发现匹配结果将匹配子串的位置加入结果集合
n++; j = next[j];
}
}
else{
j = next[j];
if( j == 0 ){
i++ , j++;
}
}
}
return n;
}
int main(){
int n , a , b , L , R;
scanf("%d%d%d%d%d",&n,&a,&b,&L,&R);
scanf("%s",P);
init(n,a,b,L,R);
int ans = KMP(S,P);
printf("%d\n",ans);
return 0;
}
计蒜客 阿里天池的新任务—简单( KMP水 )的更多相关文章
- 计蒜客 30990 - An Olympian Math Problem - [简单数学题][2018ICPC南京网络预赛A题]
题目链接:https://nanti.jisuanke.com/t/30990 Alice, a student of grade 6, is thinking about an Olympian M ...
- 计蒜客 作弊揭发者(string的应用)
鉴于我市拥堵的交通状况,市政交管部门经过听证决定在道路两侧安置自动停车收费系统.当车辆驶入车位,系统会通过配有的摄像头拍摄车辆画面,通过识别车牌上的数字.字母序列识别车牌,通过连接车管所车辆信息数据库 ...
- 计蒜客的一道题dfs
这是我无聊时在计蒜客发现的一道题. 题意: 蒜头君有一天闲来无事和小萌一起玩游戏,游戏的内容是这样的:他们不知道从哪里找到了N根不同长度的木棍, 看谁能猜出这些木棍一共能拼出多少个不同的不等边三角形. ...
- 计蒜客模拟赛5 D2T1 成绩统计
又到了一年一度的新生入学季了,清华和北大的计算机系同学都参加了同一场开学考试(因为两校兄弟情谊深厚嘛,来一场联考还是很正常的). 不幸的是,正当老师要统计大家的成绩时,世界上的所有计算机全部瘫痪了. ...
- 计蒜客 等边三角形 dfs
题目: https://www.jisuanke.com/course/2291/182238 思路: 1.dfs(int a,int b,int c,int index)//a,b,c三条边的边长, ...
- 计蒜客 方程的解数 dfs
题目: https://www.jisuanke.com/course/2291/182237 思路: 来自:https://blog.csdn.net/qq_29980371/article/det ...
- 计蒜客 买书 dfs
题目: https://www.jisuanke.com/course/2291/182236 思路: 递归解决,从第一本书开始,每本书都有两种选择: //index是book里面每本书价格的下标, ...
- 计蒜客:Entertainment Box
Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fight ...
- 爬虫acm比赛成绩(多页成绩整合在一起、获取复制不了的数据)(hihocoder、计蒜客)
https://github.com/congmingyige/web-crawler_rank-of-competition-in-JiSuanKe-and-hihocoder 1. 计蒜客(获取复 ...
随机推荐
- javascript--闭包与this
理解javascript中的闭包与this http://www.ruanyifeng.com/blog/2009/08/learning_javascript_closures.html http: ...
- 公众号和app和web都是客户端,都可以对接一个后台
1.公众号和app和web都是客户端,都可以对接一个后台 2.域名中包含端口号吗?:不包括,不包括 3.目前在IIS服务器上搭建了一个网站,域名也申请了,可是80端口不能使用,可以使用8000,每次访 ...
- UVA 10187 From Dusk Till Dawn /PC 110907
不吐槽.. #include <iostream> #include <map> #include <queue> //无语的水题.节哀吧.且这道题不严谨,因为没说 ...
- 错误总结之播放器(vitamio)音量实体键与触摸手势控制,音量调节冲突
这个但是独家心得:经过几天的网上资料查询未果,在群里遇到一同行. 然后让他帮我看了看,终于攻克了该冲突. 此时,谨以此来感谢那位同僚的热情帮助: 说说这个问题吧: 眼下我在做一款影视方面的项目,在该项 ...
- Rails 异常处理 && 性能
Rails 异常处理 的多种处理方法 1. routes match '*path', via: :all, to: 'controller#action' 2. application.rb 的 ...
- [Unit Testing] Set the timeout of a Test in Mocha
Mocha uses a default timeout of 2000 ms. However, if for some reason that does not work for your use ...
- 逻辑运算0==x和x==0具体解释
看很多大牛写的程序经常看到if(0==x){运行体},而自己写的程序常用if(x==0){运行体}.刚開始的时候我还非常自信的觉得这样的表达方式是等价的,大牛们仅仅是为了显摆下与众不同的格调.当读到C ...
- js面试题--js的继承
js是门灵活的语言,实现一种功能往往有多种做法,ECMAScript没有明白的继承机制.而是通过模仿实现的.依据js语言的本身的特性,js实现继承有下面通用的几种方式 1.使用对象冒充实现继承(该种实 ...
- 高效管理 Elasticsearch 中基于时间的索引——本质是在利用滚动模式做数据的冷热分离,热索引可以用ssd
高效管理 Elasticsearch 中基于时间的索引 转自:http://stormluke.me/es-managing-time-based-indices-efficiently/ 用 Ela ...
- python spark 决策树 入门demo
Refer to the DecisionTree Python docs and DecisionTreeModel Python docs for more details on the API. ...