POJ 3641 Oulipo KMP 水题
http://poj.org/problem?id=3461
直接KMP就好。水题
#include<cstdio>
#include<cstring>
const int MAXN=10000+10;
const int MAXM=1000000+10;
char P[MAXN],T[MAXM];
int f[MAXN],n,m,ans;
void getFail()
{
f[0]=f[1]=0;
for(int i=1;i<n;i++){
int j = f[i];
while(j && P[i] != P[j]) j=f[j];
if( P[i]==P[j]) j++;
f[i+1] = j ;
}
} void kmp()
{
int j=0;
for(int i=0;i<m;i++){
while(j && T[i] != P[j]) j=f[j];
if( T[i]==P[j]) j++;
if(j==n) ans++;
}
}
int main()
{
int kase;
scanf("%d",&kase);
while(kase--)
{
ans=0;
scanf("%s%s",P,T);
n=strlen(P);
m=strlen(T);
getFail();
kmp();
printf("%d\n",ans);
}
}
POJ 3641 Oulipo KMP 水题的更多相关文章
- POJ 1488 Tex Quotes --- 水题
POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...
- poj-2406(kmp水题)
题意:定义一个a*b=字符串a连接字符串b:给你一个字符串s,问你这个字符串最多能用多少个字符串t连接得到:例如:aaaa=4个a构成: 解题思路:kmp水题,next数组除了查找字串以外最广泛的一种 ...
- POJ Oulipo KMP 模板题
http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4 ...
- POJ Oulipo(KMP模板题)
题意:找出模板在文本串中出现的次数 思路:KMP模板题 #include<cstdio> #include<cstring> #include<cmath> #in ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
- poj 1002:487-3279(水题,提高题 / hash)
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 236746 Accepted: 41288 Descr ...
- poj 1003:Hangover(水题,数学模拟)
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 99450 Accepted: 48213 Descri ...
- poj 2105 IP Address(水题)
一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...
- poj 2000 Gold Coins(水题)
一.Description The king pays his loyal knight in gold coins. On the first day of his service, the kni ...
随机推荐
- css3.0滚动条的优化
.ass_showFriends{width: 93%;height: 8.35rem;overflow-y: auto;} .ass_showFriends::-webkit-scrollbar{w ...
- 通过 chroot 重新设置 root 密码
实例:通过 chroot 重新设置 root 密码 忘记了 root 密码该怎么办?接下来的 demo 将演示如何通过 chroot 命令重新设置 centos7 中被忘记了的 root 密码.sys ...
- JNDI学习总结(2)——JNDI数据源的配置
一.数据源的由来 在Java开发中,使用JDBC操作数据库的四个步骤如下: ①加载数据库驱动程序(Class.forName("数据库驱动类");) ②连接数据库(Con ...
- 在web开发中你不得不注意的安全验证问题#2-XSS
前言 XSS又叫CSS (Cross Site Script) ,跨站脚本攻击. 恶意攻击者往Web页面里插入恶意html代码.当用户浏览该页之时,嵌入当中Web里面的html代码会被运行,从而达到恶 ...
- 杭电(hdu)2053 Switch Game 水题
Switch Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- IIS下配置SilverLight
在Windows 2003 IIS 6.0环境下 在Silverlight中需要使用xap.XAML文件类型,如果您想在IIS服务器上使用Silverlight 4.0程序,所以必须在IIS中注册 ...
- Eclipse-ERROR
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-c ...
- HDU——T 2824 The Euler function
http://acm.hdu.edu.cn/showproblem.php?pid=2824 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- phalcon之视图缓存
phalcon官方站点上的视图缓存用法根本就是不通的 现提供一种行的通的方法例如以下: public function testAction() { if( $this->view->ge ...
- C#集合类:动态数组、队列、栈、哈希表、字典
1.动态数组:ArrayList 主要方法:Add.AddRange.RemoveAt.Remove 2.队列:Queue 主要方法:Enqueue入队列.Dequeue出队列.Peek返回Queue ...