string matching

exkmp

#include<bits/stdc++.h>
using namespace std;
const int maxn=;
int Nex[maxn],extend[maxn];
void getNex(char str[])
{
int i=,j,po,len=strlen(str);
Nex[]=len;
while(str[i]==str[i+]&&i+<len)
{
i++;
}
Nex[]=i;
po=;
for(i=; i<len; i++)
{
if(Nex[i-po]+i<Nex[po]+po)
{
Nex[i]=Nex[i-po];
}
else
{
j=Nex[po]+po-i;
if(j<)j=;
while(i+j<len&&str[j]==str[j+i])
{
j++;
}
Nex[i]=j;
po=i;
}
}
}
void Extend(char s1[],char s2[])
{
int i=,j,po,len=strlen(s1),l2=strlen(s2);
getNex(s2);
while(s1[i]==s2[i]&&i<l2&&i<len)
{
i++;
}
extend[]=i;
po=;
for(i=; i<len; i++)
{
if(Nex[i-po]+i<extend[po]+po)
{
extend[i]=Nex[i-po];
}
else
{
j=extend[po]+po-i;
if(j<)j=;
while(i+j<len&&j<l2&&s1[j+i]==s2[j])j++;
extend[i]=j;
po=i;
}
}
}
char s[];
char t[];
int main()
{
freopen("1.in","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
memset(extend,,sizeof extend);
memset(Nex,,sizeof Nex);
scanf("%s",s);
strcpy(t,s);
Extend(s,t);
int n=strlen(s);
long long ans=;
//cout<<s<<t<<endl;
for(int i=; i<=n-; i++)
{
if(i+extend[i]==n)
ans+=extend[i];
else
ans+=extend[i]+;
//cout<<extend[i]<<" "<<i<<" "<<n-1<<'\n';
}
if(n>)
ans+=;
cout<<ans<<'\n';
}
}

string matching的更多相关文章

  1. Binary String Matching

    问题 B: Binary String Matching 时间限制: 3 Sec  内存限制: 128 MB提交: 4  解决: 2[提交][状态][讨论版] 题目描述 Given two strin ...

  2. NYOJ之Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述     Given two strings A and B, whose a ...

  3. ACM Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  4. 南阳OJ----Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  5. Binary String Matching(kmp+str)

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  6. Aho - Corasick string matching algorithm

    Aho - Corasick string matching algorithm 俗称:多模式匹配算法,它是对 Knuth - Morris - pratt algorithm (单模式匹配算法) 形 ...

  7. [POJ] String Matching

    String Matching Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4074   Accepted: 2077 D ...

  8. String Matching Content Length

    hihocoder #1059 :String Matching Content Length 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 We define the ...

  9. NYOJ 5 Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  10. (find) nyoj5-Binary String Matching

    5-Binary String Matching 内存限制:64MB 时间限制:3000ms 特判: No通过数:232 提交数:458 难度:3 题目描述: Given two strings A ...

随机推荐

  1. [19/06/05-星期三] CSS基础_样式表的位置(内联、内部、外部样式)、块元素(div)、内联元素(span)、常用的选择器

    一.概念 CSS(Cascading Style Sheets,层叠样式表) 可以用来为网页创建样式表,通过样式表可以对网页进行装饰. 所谓层叠,就是可以将整个网页想象成是一层一层的结构,层次高的将会 ...

  2. MySQL-快速入门(2)数据类型

    1.MySQL支持多种数据类型: 1>数值类型:整数类型tinyint.smallint.mediumint.bigint.int:浮点小数类型float.double:定点小数类型decima ...

  3. 分布式事务解决方案汇总:2PC、3PC、消息中间件、TCC、状态机+重试+幂等(转)

    数据一致性问题非常多样,下面举一些常见例子.比如在更新数据的时候,先更新了数据库,后更新了缓存,一旦缓存更新失败,此时数据库和缓存数据会不一致.反过来,如果先更新缓存,再更新数据库,一旦缓存更新成功, ...

  4. Composer 的自动加载机制

    Composer 的自动加载机制 Composer 提供了四种自动加载方式,分别是 PSR-0.PSR-4.生成 classmap 以及之间包含 files. PSR-0 方式 PSR-0 方式要求目 ...

  5. 使用SecureCRT 8.5快速打开sftp传输文件

    一般使用Windows系统上安装的SecureCRT 8.5软件远程连接Linux服务器,通常给Linux系统传输文件或者使用FTP,或者使用SFTP等其他第三方软件,有时Linux系统上还需要做其他 ...

  6. 计算机系统结构总结_Branch prediction

    Textbook:<计算机组成与设计——硬件/软件接口>  HI<计算机体系结构——量化研究方法>          QR Branch Prediction 对于下面的指令: ...

  7. “百度杯”CTF比赛 十一月场--CrackMe01

    测试文件:https://static2.ichunqiu.com/icq/resources/fileupload/CTF/BSRC/BSRC-11-3/CrackMe01_97D2BF0DBD2E ...

  8. Python webdriver调用Chrome报错

    报错信息如下: selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to b ...

  9. 划水日记之大哥带我走渗透I

    5/24/19 周五 access注入 先测试是否有漏洞 or nor and 1=1 and 1=2 2. Order by 猜字表端,发现一共有22个 3..然后使用 union select 1 ...

  10. EffectiveC++01-03

    导读 作者Scott Meyers在如何有效运用C++方面给出了55个具体的做法,大致分为两类: 一般性的设计策略,集中于"如何在不同的做法中选择一种完成任务" 选择inherit ...