SDUTOJ 2475 Power Strings
<pre class="cpp" name="code">#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 1000005
int next[N];
char s[N];
using namespace std;
void getnext(char s[])//KMP算法的应用
{
int j=-1,i=0,len;
next[0]=-1;
len=strlen(s);
while(i<=len)
{
if(j==-1||s[i]==s[j])
{
++i;
++j;
next[i]=j;
}
else
j=next[j];
}
}
int main()
{
int len;
while(cin>>s)
{
if(s[0]=='.')
{
break;
}
len=strlen(s);
getnext(s);
if(len%(len-next[len])==0)
cout<<(len/(len-next[len]))<<endl;//求最小循环节..事实上题意就是这个意思
}
return 0;
}
SDUTOJ 2475 Power Strings的更多相关文章
- POJ 2406 Power Strings (KMP)
Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...
- POJ 2406 Power Strings
F - Power Strings Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- poj 2406:Power Strings(KMP算法,next[]数组的理解)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30069 Accepted: 12553 D ...
- POJ 2406:Power Strings
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 41252 Accepted: 17152 D ...
- E - Power Strings,求最小周期串
E - Power Strings Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- poj 2406 Power Strings kmp算法
点击打开链接 Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27368 Accepted: ...
- poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)
http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submiss ...
- 【POJ2406】 Power Strings (KMP)
Power Strings Description Given two strings a and b we define a*b to be their concatenation. For exa ...
- Power Strings
Power Strings TimeLimit: 1 Second MemoryLimit: 32 Megabyte Totalsubmit: 1791 Accepted: 528 Descr ...
随机推荐
- 框架—Mybatis搭建
1:导包 完整jar包:mybatis核心包+依赖包+mysqljdbc驱动包 2. 建库建表 3.实体类 4.映射文件 一般dao的包下 5.主配置文件(mybatisconfig.xml) 一般s ...
- More Effective C++ - 章节二 : 操作符(operators)
5. 对定制的 "类型转换函数" 保持警觉 允许编译器执行隐式类型转换,害处多过好处,不要提供转换函数,除非你确定需要. class foo { foo(int a = 0, in ...
- 条款36:绝不重新定义继承而来的non-virtual函数(Never redefine an inherited non-virtual function)
NOTE: 1.绝对不要重新定义继承而来的non-virtual函数.
- pwnable.kr blackjack之write up
首先我们按提示找到源代码,看这一段: int betting() //Asks user amount to bet { printf("\n\nEnter Bet: $"); s ...
- 【HDU 6000】Wash(贪心)
Problem Description Mr.Panda is about to engage in his favourite activity doing laundry! He's brough ...
- SpringCloud源码地址
SpringCloud实战源代码 https://github.com/springcloud/spring-cloud-code.git
- zoj 2736 Daffodil number
Daffodil number Time Limit: 2 Seconds Memory Limit: 65536 KB The daffodil number is one of the ...
- HDU1757-A Simple Math Problem,矩阵快速幂,构造矩阵水过
A Simple Math Problem 一个矩阵快速幂水题,关键在于如何构造矩阵.做过一些很裸的矩阵快速幂,比如斐波那契的变形,这个题就类似那种构造.比赛的时候手残把矩阵相乘的一个j写成了i,调试 ...
- D 题
题目大意:找朋友,最好把朋友最多的一堆的人数输出 运用并查集,每次更新最大数即可: 代码: #include <iostream> #include <cstdio> #inc ...
- [luoguP3258] [JLOI2014]松鼠的新家(lca + 树上差分)
传送门 需要把一条路径上除了终点外的所有数都 + 1, 比如,给路径 s - t 上的权值 + 1,可以先求 x = lca(s,t) 类似数列上差分的思路,可以给 s 和 f[t] 的权值 + 1, ...