题意:定义一个a*b=字符串a连接字符串b;给你一个字符串s,问你这个字符串最多能用多少个字符串t连接得到;例如:aaaa=4个a构成;

解题思路:kmp水题,next数组除了查找字串以外最广泛的一种用法,用来判定一个串是不是循环串,如果是,输出原串的长度/最小的循环节,否则,输出1就行了;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1000500
using namespace std;
int next[maxn];
char t[maxn];
int tlen;
void get_next()
{
int j=0,k=-1;next[0]=-1;
while(j<tlen)
{
if(k==-1||t[j]==t[k])
next[++j]=++k;
else
k=next[k];
}
}
int main()
{
while(gets(t))
{
tlen=strlen(t);
if(strcmp(t,".")==0)
break;
get_next();
int len=tlen-next[tlen];
if(tlen%len==0)
{
printf("%d\n",tlen/len);
}
else
{
printf("1\n");
}
//printf("%d\n",ans);
}
}

  

poj-2406(kmp水题)的更多相关文章

  1. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  2. POJ 3641 Oulipo KMP 水题

    http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...

  3. POJ Oulipo KMP 模板题

    http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4 ...

  4. poj 3264 RMQ 水题

    题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...

  5. Poj 1552 Doubles(水题)

    一.Description As part of an arithmetic competency program, your students will be given randomly gene ...

  6. POJ Oulipo(KMP模板题)

    题意:找出模板在文本串中出现的次数 思路:KMP模板题 #include<cstdio> #include<cstring> #include<cmath> #in ...

  7. POJ 2406 KMP/后缀数组

    题目链接:http://poj.org/problem?id=2406 题意:给定一个字符串,求由一个子串循环n次后可得到原串,输出n[即输出字符串的最大循环次数] 思路一:KMP求最小循环机,然后就 ...

  8. poj(2406) kmp

    题目链接:https://vjudge.net/problem/POJ-2406 kmp学习:https://blog.csdn.net/starstar1992/article/details/54 ...

  9. POJ 3080 (字符串水题) Blue Jeans

    题意: 找出这些串中最长的公共子串(长度≥3),如果长度相同输出字典序最小的那个. 分析: 用库函数strstr直接查找就好了,用KMP反而是杀鸡用牛刀. #include <cstdio> ...

随机推荐

  1. python--Numpy and Pandas 笔记01

    博客地址:http://www.cnblogs.com/yudanqu/ 1 import numpy as np import pandas as pd from pandas import Ser ...

  2. 字典 dict

    # --------------------------我愿作一叶小舟,驶向远方.----------------------------------------------------------- ...

  3. python_内置函数1_42

    内置函数 内置函数大全:     Built-in Functions     abs() dict() help() min() setattr() all() dir() hex() next() ...

  4. H5 15-交集选择器

    15-交集选择器 我是段落 我是段落 我是段落 我是段落 我是段落 <!DOCTYPE html> <html lang="en"> <head> ...

  5. Python魔法函数

    python中定义的以__开头和结尾的的函数.可以随意定制类的特性.魔法函数定义好之后一般不需要我们自己去调用,而是解释器会自动帮我们调用. __getitem__(self, item) 将类编程一 ...

  6. 把玩Alpine linux(二):APK包管理器

    导读 Alpine Linux非常精简,开机内存占用也在二三十兆大,没有拆箱即用,就需要我们自己去做一些了解和配置 Alpine Linux的优劣 优势 Alpine Linux的Docker镜像特点 ...

  7. centos开启ftp服务的步骤

    1.安装vsftpd sudo yum install vsftpd -y 2.启动ftp服务 service vsftpd start 3.  加入开机启动 chkconfig vsftpd on ...

  8. python中filter(),reduce()函数

    filter()函数 是 Python 内置的另一个有用的高阶函数,filter()函数接收一个函数 和一个list,这个函数的作用是对每个元素进行判断,返回 True或 False,filter() ...

  9. Mysql的使用,常用的SQL语句

    一.启动mysql服务 启动mysql服务: systemctl start mysqld.service root用户登录mysql: 修改root 密码: alter user 'root'@'l ...

  10. C++实现算法常用的STL---整理

    algorithm min(a,b)和max(a,b) #include<iostream> #include<algorithm> using namespace std; ...