xtu字符串 B. Power Strings
B. Power Strings
64-bit integer IO format: %lld Java class name: Main
Input
Output
Sample Input
abcd
aaaa
ababab
.
Sample Output
1
4
3
Hint
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
#define INF 0x3f3f3f
using namespace std;
const int maxn = ;
char str[maxn];
int fail[maxn];
void getFail(int &len) {
int i,j;
len = strlen(str);
fail[] = fail[];
for(i = ; i < len; i++) {
j = fail[i];
while(j && str[j] != str[i]) j = fail[j];
fail[i+] = str[j] == str[i] ? j+:;
}
}
int main() {
int len;
while(gets(str) && str[] != '.') {
getFail(len);
if(len%(len-fail[len])) puts("");
else printf("%d\n",len/(len-fail[len]));
}
return ;
}
xtu字符串 B. Power Strings的更多相关文章
- poj 2406 Power Strings【字符串+最小循环节的个数】
Po ...
- UVA - 10298 Power Strings (KMP求字符串循环节)
Description Problem D: Power Strings Given two strings a and b we define a*b to be their concatenati ...
- POJ 2406 Power Strings (KMP)
Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...
- 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 中 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 ...
随机推荐
- h5-29-WEB存储-通讯录实战.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 宏 函数 内联函数inline
带参宏有时候可以代替函数作用:优点直接替代,省去函数调用过程的开销:但缺点也是很明显:容易出错,系统不做检查非常容易出错. 改进方案:内联函数:既有带参宏的直接替代(拷贝)的优点,又有系统检查的优点. ...
- 02.第二章_C++ Primer学习笔记_变量和基本类型
2.1 基本内置类型 2.1.1 算术类型 算术类型包括两类:整型和浮点型 2.2 变量 2.3 复合类型 2.4 const限定符 2.5 处理类型 2.6 自定义数据结构
- Java基础学习-一切皆为对象
一切皆为对象 引用 String s; //s是引用,并不是对象. String s = "asdf" //创建一个引用的同时便进行初始化
- EditText输入手机号自动带空格
xml: <EditText android:id="@+id/edit_main" android:layout_width="match_parent" ...
- 实现流水灯以间隔500ms的时间闪烁(系统定时器SysTick实现的精确延时)
/** ****************************************************************************** * @file main.c * ...
- javascript中 if(变量)和if(变量==true)的区别
if(判断表达式){执行内容} 如果判断表达式为true,则执行括号中的内容.这里,变量如果不为0,null,undefined,false,都会被处理为true.只要变量有非0的值或是某个对象,数组 ...
- 手写MVVM框架 之vue双向数据绑定原理剖析
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- vue项目中常用的一些公共方法
//校验手机号码 export function isSpecialPhone(num) { return /^1[2,3,4,5,7,8]\d{9}$/.test(num) } //校验中英文姓名 ...
- MongoDB最简单的入门教程之二 使用nodejs访问MongoDB
在前一篇教程 MongoDB最简单的入门教程之一 环境搭建 里,我们已经完成了MongoDB的环境搭建. 在localhost:27017的服务器上,在数据库admin下面创建了一个名为person的 ...