2016暑假多校联合---Another Meaning
Today, ?? is chating with MeiZi online, MeiZi sends a sentence A to ??. ?? is so smart that he knows the word B in the sentence has two meanings. He wants to know how many kinds of meanings MeiZi can express.
Each test case contains two strings A and B, A means the sentence MeiZi sends to ??, B means the word B which has two menaings. string only contains lowercase letters.
Limits
T <= 30
|A| <= 100000
|B| <= |A|
In the first case, “ hehehe” can have 3 meaings: “*he”, “he*”, “hehehe”.
In the third case, “hehehehe” can have 5 meaings: “*hehe”, “he*he”, “hehe*”, “**”, “hehehehe”.
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const long long mod=1e9+; char s[];
char ss[];
int next1[];
long long num[];
int pos[]; void makenext1(const char P[])
{
int q,k;
int m = strlen(P);
next1[]=;
for (q = ,k = ; q < m; ++q)
{
while(k > && P[q] != P[k])
k = next1[k-];
if (P[q] == P[k])
{
k++;
}
next1[q] = k;
}
} long long calc(char T[],char P[])
{
int n,m;
int i,q;
int tot=;
n = strlen(T);
m = strlen(P);
makenext1(P);
for(i=,q = ; i < n; ++i)
{
while(q>&&P[q]!=T[i])
q=next1[q-];
if(P[q]==T[i])
{
q++;
}
if(q==m)
{
long long flag=;
pos[tot]=i-m+;
if(tot>)
{
if(pos[tot-]+m<=pos[tot])
{
num[tot]=(*num[tot-])%mod;
}
else
{
num[tot]=num[tot-]%mod;
for(int h=tot-;h>=;h--)
{
if(pos[h]+m<=pos[tot])
{
num[tot]=(num[tot]+num[h])%mod;
flag=; ///当之前不存在不相重叠的语句时;
break;
}
}
num[tot]=(num[tot]+flag)%mod;
}
}
else
{
num[tot]=;
}
tot++;
}
}
if(tot==) return ;
return num[tot-];
} int main()
{
int T;
int Case=;
cin>>T;
while(T--)
{
scanf("%s%s",s,ss);
printf("Case #%d: %lld\n",Case++,calc(s,ss));
// cout<<(calc(s,ss)%mod+mod)%mod<<endl;
}
return ;
}
2016暑假多校联合---Another Meaning的更多相关文章
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- 2016暑假多校联合---Substring(后缀数组)
2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...
- 2016暑假多校联合---To My Girlfriend
2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...
- 2016暑假多校联合---A Simple Chess
2016暑假多校联合---A Simple Chess Problem Description There is a n×m board, a chess want to go to the po ...
- 2016暑假多校联合---Death Sequence(递推、前向星)
原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historia ...
- 2016暑假多校联合---Counting Intersections
原题链接 Problem Description Given some segments which are paralleled to the coordinate axis. You need t ...
- 2016暑假多校联合---Joint Stacks (STL)
HDU 5818 Problem Description A stack is a data structure in which all insertions and deletions of e ...
- 2016暑假多校联合---GCD
Problem Description Give you a sequence of N(N≤100,000) integers : a1,...,an(0<ai≤1000,000,000). ...
随机推荐
- Atitti 数据库事务处理 attilax总结
Atitti 数据库事务处理 attilax总结 1.1. 为什么要传递Connection?1 1.2. 两种事务处理方式,一种是编程式事务处理;一种是声明...2 1.3. 事务隔离级别 2 1. ...
- Jenkins+MSbuild+SVN实现dotnet持续集成 快速搭建持续集成环境
Jenkins是一个可扩展的持续集成引擎,Jenkins非常易于安装和配置,简单易用,下面开始搭建dotnet持续集成环境 一.准备工作 1.系统管理-->管理插件-->可选插件中找到MS ...
- oracle11g AUD$维护
SYSTEM表空间使用率达到了85%,查出是用来记录审计记录的aud$表占用了很大的空间. 备份后truncate掉AUD$,问题临时解决.记得oracle11.2可以把aud$迁移到普通的表空 间. ...
- SQL Server的日期和时间类型
Sql Server使用 Date 表示日期,time表示时间,使用datetime和datetime2表示日期和时间. 1,秒的精度是指使用多少位小数表示秒 DateTime数据类型秒的精度是3,D ...
- 信息加密之消息摘要算法的MAC
MAC是消息摘要算法的第三种实现方式,另外两种方式分别为:MD2\4\5.SHA. MAC的jdk实现:1.默认密钥方式 private static void MAC_JDK(){ try { Ke ...
- ZooKeeper官方文档翻译——ZooKeeper Overview 3.4.6
ZooKeeper ZooKeeper: A Distributed Coordination Service for Distributed Applications (针对分布式应用的分布式调度服 ...
- Android notification的使用
notification出现在通知栏中的提示,特别是在4.0以后改进了不少,这里讲得都是基于4.0及4.1以后的. 分类: 1.普通Notification 2.大布局Notification 图1 ...
- Windows Azure HandBook (3) 浅谈Azure安全性
<Windows Azure Platform 系列文章目录> 2015年3月5日-6日,参加了上海的Azure University活动.作为桌长与微软合作伙伴交流了Azure相关的技术 ...
- Elasticsearch 之 数据索引
对于提供全文检索的工具来说,索引时一个关键的过程——只有通过索引操作,才能对数据进行分析存储.创建倒排索引,从而让使用者查询到相关的信息. 本篇就ES的数据索引操作相关的内容展开: 更多内容参考:El ...
- 基于HTML5的WebGL呈现A星算法3D可视化
http://www.hightopo.com/demo/astar/astar.html 最近搞个游戏遇到最短路径的常规游戏问题,一时起兴基于HT for Web写了个A*算法的WebGL 3D呈现 ...